gpt4 book ai didi

java - setOnItemLongClickListener 和 setOnItemClickListener 在同一个类上

转载 作者:行者123 更新时间:2023-12-01 09:37:03 26 4
gpt4 key购买 nike

我的问题是这样的:当我长按项目时,会出现两个 View 。

请参阅下面我的 java 类代码。请帮忙。

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

Intent intent = new Intent(MyGoodsActivity.this, CurrentActivity.class);
Bundle bundle = new Bundle();
bundle.putLong(Record.BUNDLE_SHOP_ID, mShopId);
bundle.putLong(Record.BUNDLE_the_ID, mGoodsAdapter.getItemId(position));
intent.putExtras(bundle);
MyGoodsActivity.this.startActivity(intent);
}



});

mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {



@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {




AlertDialog.Builder dialog = new AlertDialog.Builder(MyGoodsActivity.this);
dialog.setTitle(R.string.tip);
dialog.setMessage(R.string.info_confirm_delete_this_item);
dialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
MyDB db = new MyDB(MyGoodsActivity.this);
db.deleteGoodsById(mGoodsAdapter.getItemId(position));
refreshListgoods();
}
});
dialog.setNegativeButton(R.string.ko, null);
dialog.show();
return false;
}
}


);

最佳答案

分析我的代码后,我只需返回 true 即可解决我的问题。

            dialog.setNegativeButton(R.string.ko, null);
dialog.show();
return true;
}

关于java - setOnItemLongClickListener 和 setOnItemClickListener 在同一个类上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38816956/

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