我有4个按钮选项,没有点击任何一个选项,我正在进入下一页,它应该显示一个警告对话框。
如果(btnOpt_1.equals(btnOpt_1)及;&安培; btnOpt_2.equals(btnOpt_2)及;&安培; btnOpt_3.equals(btnOpt_3)|| btnOpt_4.equals(btnOpt_4)|| btnOpt_5.equals(btnOpt_5)){< / p>
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Feedback.this);
// Setting Dialog Title
alertDialog.setTitle("OOPs");
// Setting Dialog Message
alertDialog.setMessage("You can't proceed without selecting");
// Setting Icon to Dialog
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
// Write your code here to invoke YES event
Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
// Setting Negative "NO" Button
// Showing Alert Message
alertDialog.show();
}
}
答案 0 :(得分:0)
试试这个...在ui线程上运行你的警告对话框......
if(btnOpt_1.equals(btnOpt_1)&&btnOpt_2.equals(btnOpt_2)&&btnOpt_3.equals(btnOpt_3)||btnOpt_4.equals(btnOpt_4)||btnOpt_5.equals(btnOpt_5)){
runOnUiThread(new Runnable() {
@override
public void run() {
if(!isFinishing()){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Feedback.this);
// Setting Dialog Title
alertDialog.setTitle("OOPs");
// Setting Dialog Message
alertDialog.setMessage("You can't proceed without selecting");
// Setting Icon to Dialog
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
// Write your code here to invoke YES event
Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
// Setting Negative "NO" Button
// Showing Alert Message
alertDialog.show();
}
});
}