在數組中獲取選中項目的值,代碼:
final String items[] = {"Blue","Green","Orange"};
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Money Maker");
alert.setIcon(R.drawable.ic_launcher);
alert.setMultiChoiceItems(items, checkedItems, new
DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
String value = items.toString();
Toast.makeText(getApplication(), value, Toast.LENGTH_LONG).show();
}
});
alert.show();
怎麼獲取值並且在toast中顯示?謝謝。
應該是:
alert.setMultiChoiceItems(items, checkedItems, new
OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which, boolean isChecked) {
Toast.makeText(getApplication(), items[which], Toast.LENGTH_LONG).show();
}
});