直接上代码吧!
public class AlertDialogUsage extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new AlertDialog.Builder(AlertDialogUsage.this)
.setTitle("Powe level")
.setMessage("Griffin's AlertDialog sample!")
.setPositiveButton("Yes",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
Log.d("TAG","[setPositiveButton]");
}
}
)
.setNegativeButton("No", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
Log.d("TAG","[setNegativeButton]");
}
}
)
.show();
}
}
AlertDialog使用示例
本文提供了一个简单的AlertDialog使用示例,展示了如何创建一个带有确认和取消按钮的对话框,并为每个按钮设置点击监听器。
767

被折叠的 条评论
为什么被折叠?



