gpt4 book ai didi

android - 在单选警报对话框中启用/禁用肯定按钮

转载 作者:搜寻专家 更新时间:2023-11-01 08:01:10 25 4
gpt4 key购买 nike

如果您能帮我解决这个问题,我有一个包含 3 个选项的单选警报对话框。我最初禁用了 NEXT 按钮(没有选择任何选项)。当用户选择任何选项时,我想启用 NEXT 按钮。这是我试过的代码。

int involvementInIncident;

case DIALOG_ADD_A_PERSON_INVOLVEMENT_ONE:

builder.setTitle("Involvement in this Incident");
builder.setSingleChoiceItems(incidentInvolvement, -1,
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

involvementInIncident = which;
//involvementInIncident = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
Toast.makeText(getApplicationContext(),""+ involvementInIncident, Toast.LENGTH_SHORT).show();


}
});
builder.setPositiveButton("Next",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(),""+ involvementInIncident, Toast.LENGTH_SHORT).show();
showDialog(DIALOG_ADD_A_PERSON_PERSON_TYPE_TWO);

}

});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();


}
});
AlertDialog alertInvolvement = builder.create();
alertInvolvement.show();
final Button buttonPositiveInvolvement = alertInvolvement.getButton(AlertDialog.BUTTON_POSITIVE);
buttonPositiveInvolvement.setEnabled(false);

if(involvementInIncident == 0 || involvementInIncident == 1 || involvementInIncident==2){
buttonPositiveInvolvement.setEnabled(true);
//Toast.makeText(getApplicationContext(),"person responsiblee", Toast.LENGTH_SHORT).show();

}
else
{
buttonPositiveInvolvement.setEnabled(false);
}

return dialog;

非常感谢您的帮助。谢谢

最佳答案

终于搞定了。感谢 Piyush 和 Mystic Magic 的帮助。在这里发布代码,可能会对其他人有所帮助。全局初始化的buttonPositiveInvolvement按钮buttonPositiveInvolvement;

总结:在选择项目时启用/禁用单选 AlertDialog 中的肯定按钮。 (最初 NEXT 按钮被禁用,当一个项目被选中时它启用 NEXT 按钮)

//全局按钮buttonPositiveInvolvement;

案例 DIALOG_ADD_A_PERSON_INVOLVEMENT_ONE:

        builder.setTitle("Involvement in this Incident");   
builder.setSingleChoiceItems(incidentInvolvement, -1,
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
//to enable the the NEXT button
buttonPositiveInvolvement.setEnabled(true);

}
});
builder.setPositiveButton("Next",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

showDialog(DIALOG_ADD_A_PERSON_PERSON_TYPE_TWO);

}

});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();


}
});
//This sequence needs to be followed to get it working or else it might screw up
AlertDialog alertInvolvement = builder.create();
alertInvolvement.show();
buttonPositiveInvolvement = alertInvolvement.getButton(AlertDialog.BUTTON_POSITIVE);
buttonPositiveInvolvement.setEnabled(false);

return dialog;

关于android - 在单选警报对话框中启用/禁用肯定按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21043230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com