0
我有以下對話框代碼,但問題在於選擇在我按下OK按鈕之前生效。我應該怎麼做才能使選擇在按下OK按鈕後生效?Android對話框不在等待確定按鈕
public void cropSelect()
{
final CharSequence[] cropType = {"Wheat","Corn","Soybean"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainContext.myContext);
builder.setTitle("Choose Crop");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
builder.setSingleChoiceItems(cropType, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if("Wheat".equals(cropType[which])){
cropSelect = "Wheat";
}
else if("Corn".equals(cropType[which])){
cropSelect = "Corn";
}
else if("Soybean".equals(cropType[which])){
cropSelect = "Soybean";
}
}
});
builder.show();