android之具有选择功能的AlertDialog
主要代码:
<textarea cols="50" rows="15" name="code" class="c-sharp">new AlertDialog.Builder(Main.this) .setTitle(R.string.str_alert_title) .setItems(R.array.item_irdc_dialog, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { String[] aryShop = getResources().getStringArray(R.array.item_irdc_dialog); CharSequence dialogBody = getResources().getString(R.string.str_alert_body); new AlertDialog.Builder(Main.this) .setMessage(dialogBody+aryShop[which]) .setNeutralButton(R.string.str_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which1) { // } }) .show(); } }).show(); return; </textarea>
strings.xml:
<textarea cols="50" rows="15" name="code" class="c-sharp"><?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, Main!</string> <string name="app_name">DearHelper</string> <string name="str_alert_title">按我开始选择</string> <string name="str_alert_body">你选择的是:</string> <string name="str_ok">确定</string> <string-array name="item_irdc_dialog"> <item>火锅</item> <item>川菜</item> <item>淮扬菜</item> <item>陇菜</item> </string-array> </resources> </textarea>