How to get index value when user checked listview from android alertdialog
List<String> ShowView = new ArrayList<String>();
final CharSequence[] Animals = ShowView.toArray(new String[ShowView.size()]);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TestActivity.this);
dialogBuilder.setTitle("ListView");
dialogBuilder.setItems(Animals, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
//This get index value!!
}
});
AlertDialog alertDialogObject = dialogBuilder.create();
alertDialogObject.show();
您正在寻找DialogInterface.OnClickListener()
给出的int item
。
Int item is the index of clicked item .
final CharSequence[] Animals= ShowView.toArray(new String[ShowView.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("ListView");
builder.setItems(Animals, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
String val=String.valueOf(Animals[item]);// this is value
}
});
builder.show();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.