Java 负面和正面按钮在emulator上不起作用
当我在警报对话框中Java 负面和正面按钮在emulator上不起作用,java,android,Java,Android,当我在警报对话框中setNegativeButton和setPositiveButton时,当我在我的移动设备(Hauwei手机)上运行它时。运行非常完美,但是当我在模拟器上运行它时,alertDialog显示但不显示“确定”或“取消”,但我仍然可以单击它们,就像看不见或什么的,有人能帮我吗 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onIt
setNegativeButton
和setPositiveButton
时,当我在我的移动设备(Hauwei手机)上运行它时。运行非常完美,但是当我在模拟器上运行它时,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();
}
});
listView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
公共视图单击(适配器视图a、视图v、内部位置、长id){
AlertDialog.Builder alertD=新建AlertDialog.Builder(Report.this);
alertD.setTitle(“删除?”);
alertD.setMessage(“您确定要删除您的Bmi吗”);
最终int位置ToRemove=位置;
alertD.setNegativeButton(“确定”,空);
setPositiveButton(“取消”,新建AlertDialog.OnClickListener()){
public void onClick(DialogInterface dialog,int which){
bmis.移除(位置移除);
b、 notifyDataSetChanged();
}});
alertD.show();
}
});
在您的鼠标内
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();
使用“确定为负数”按钮是不正确的。因此,我使用“是”作为正数,使用“取消”作为负数,并且您不希望将位置作为额外变量保留为
final int position to remove=position
。您可以直接使用它。是的,很抱歉,在更改代码时,我将“确定”和“取消”放在了错误的位置以进行检查。我现在就试试。非常感谢。我刚刚做了最后的决定。现在运行模拟器测试itah是的,您需要将其设置为最终。bmis是您的项目列表,b是您的适配器,对吗?否按钮仍然不显示“是”或“取消”,它们是它们的按钮,但不可见???