首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

打开程序在activity下出现一个AlertDialog

2012-07-04 
打开程序在activity上出现一个AlertDialog只要把? showDialog(0) 写在oncreat里,这样打开应用就会加载。pu

打开程序在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;

? ? ? ? ? ? }

? ? ? ? }

? ? }

?

?

?

?

?

?

}

热点排行