当我在警告对话框中setNegativeButton
和setPositiveButton
时,我在我的移动设备上运行它,这是一个Hauweii手机。运行完美,但是当我在模拟器上运行时,alertDialog
显示但是没有显示确定或取消但我仍然可以点击它们,它就像是看不见的东西,有人可以帮助我吗?
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
AlertDialog.Builder alertD=new AlertDialog.Builder(Report.this);
alertD.setTitle("Delete?");
alertD.setMessage("Are you sure you want to delete your Bmi ");
final int positionToRemove = position;
alertD.setNegativeButton("Ok", null);
alertD.setPositiveButton("Cancel", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
bmis.remove(positionToRemove);
b.notifyDataSetChanged();
}});
alertD.show();
}
});
答案 0 :(得分:0)
在onItemClick
中AlertDialog.Builder alertDialog = new AlertDialog.Builder(Report.this);
final int positionToRemove = position;
alertDialog.setTitle("Delete?");
alertDialog.setMessage("Are you sure you want to delete your Bmi "));
// Setting Positive "YES" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
bmis.remove(positionToRemove);
b.notifyDataSetChanged();
dialog.dismiss();
}
});
// Setting Negative "CANCEL" Button
alertDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
// Showing Alert Message
alertDialog.show();