gpt4 book ai didi

java - OnItemLongClickListener 在释放按钮时也会运行 OnItemClickListener

转载 作者:行者123 更新时间:2023-12-02 10:48:19 26 4
gpt4 key购买 nike

它使用函数 OnItemLongClickListener 但在释放按钮时也会运行 OnItemClickListener

    lv_driver.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {

builder = new AlertDialog.Builder(MyActivity.this);
builder.setTitle("Be carefull ");
builder.setMessage("Do you want to delete?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

delData(i);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});

builder.show();

return false;
}
});

lv_driver.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

Toast.makeText(MyActivity.this, "OnItemclick show ",
Toast.LENGTH_SHORT).show();
}
});

}

当按住按钮时,它会显示对话框确认删除,但当释放按钮时,它会显示 toast 中的文本“OnItemclick show”。如何解决?

最佳答案

只需返回 true; 而不是在 setOnItemLongClickListener 中返回 false,它必须做到这一点

更改此

 lv_driver.setOnItemLongClickListener(new 
AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view,
int i, long l) {

builder = new AlertDialog.Builder(MyActivity.this);
builder.setTitle("Be carefull ");
builder.setMessage("Do you want to delete?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

delData(i);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});

builder.show();

return false;
}
});

到此

     lv_driver.setOnItemLongClickListener(new 
AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view,
int i, long l) {

builder = new AlertDialog.Builder(MyActivity.this);
builder.setTitle("Be carefull ");
builder.setMessage("Do you want to delete?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

delData(i);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});

builder.show();

return true;
}
});

关于java - OnItemLongClickListener 在释放按钮时也会运行 OnItemClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52374256/

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