打开程序在activity上出现一个AlertDialog
只要把? showDialog(0); 写在oncreat里,这样打开应用就会加载。
public class Test extends Activity {
? ? /** Called when the activity is first created. */
? ? @Override
? ? public void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.main);
? ? ? ? showDialog(0);
? ? ? ? Button button1 = (Button) findViewById(R.id.button1);
? ? ? ? button1.setOnClickListener(new Button.OnClickListener() {
?
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? showDialog(0);
? ? ? ? ? ? }
? ? ? ? });
?
? ? }
?
? ? @Override
? ? protected Dialog onCreateDialog(int id) {
? ? ? ? switch (id) {
? ? ? ? ? ? case 0: {
? ? ? ? ? ? ? ? Dialog dialog = new AlertDialog.Builder(Test.this).setTitle("Question")
? ? ? ? ? ? ? ? ? ? ? ? .setMessage("Are you sure that you want to quit?") // 设置内容
? ? ? ? ? ? ? ? ? ? ? ? .setPositiveButton("Yes", // 设置确定按钮
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog, int whichButton) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? setResult(RESULT_OK);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? finish();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }).setNegativeButton("No", new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog, int whichButton) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }).create();// 创建
? ? ? ? ? ? ? ? return dialog;
? ? ? ? ? ? }
? ? ? ? ? ? default: {
? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? }
? ? ? ? }
? ? }
?
?
?
?
?
?
}