如何从AlertDialog
获取所选项目文本AlertDialog.Builder b = new AlertDialog.Builder(SettingsCustom.this);
b.setTitle("Example");
String[] types = {"Item 1","Item 2","Item 3" };
b.setItems(types, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
//How to get the selected text
}
});
b.show();
答案 0 :(得分:0)
我找到了办法。但不知道这是不是最好的方式。
AlertDialog.Builder b = new AlertDialog.Builder(SettingsCustom.this);
b.setTitle("Example");
final String[] types = {"Item 1","Item 2","Item 3" };
b.setItems(types, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
//How to get the selected text
Log.v("-----> " , "selected text = " + types[which]);
}
});
b.show();
答案 1 :(得分:0)
您需要注册DialogInterface.OnClickListener并使用setPostivie,setsinglechoice,setmultichoice等方法。