首页 > 代码库 > AlertDialog的写法

AlertDialog的写法

 1 public void onItemClick(AdapterView<?> parent, View view, int position,long id) { 2         AlertDialog.Builder builder = new AlertDialog.Builder(this); 3         builder.setTitle("选项"); 4         builder.setItems(R.array.choice, new DialogInterface.OnClickListener() { 5             @Override 6             public void onClick(DialogInterface dialog, int which) { 7                 switch(which) { 8                 case 0: 9                     break;10                 case 1:11                     break;12                 case 2:13                     break;14                 }15                 16             }17         });18         builder.setNegativeButton("取消", null);19         builder.create().show();20         21     }

 

 

string.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3  4     <string name="app_name">AppExplorer</string> 5     <string name="hello_world">Hello world!</string> 6     <array name ="choice"> 7         <item name="start">启动程序</item> 8         <item name="detail">详细信息</item> 9         <item name="uninstall">卸载</item>10     </array>11 </resources>

效果:

AlertDialog的写法