本文介绍了同时使用setOnItemClickListener和setOnItemLongClickListener这两个侦听器会同时触发或同时触发.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ListView
中,我同时使用setOnItemClickListener()
和setOnItemLongClickListener()
.当我单击某个项目时,它可以正常工作,但是当我长时间单击某个项目时,有时两个监听器会同时触发或同时工作.为什么?
In ListView
I am using both setOnItemClickListener()
and setOnItemLongClickListener()
. When I click on an item it works fine but when I long-click on an item sometimes both listeners are fired at same time or work at same time. Why?
/**
* on click of list view item show the run time webview.
*/
mListViewStar.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
isHome = true;
Animation translate1 = AnimationUtils.loadAnimation(Home.this,
R.anim.tran_right);
mRelativeLayout.setVisibility(View.GONE);
mRelativeLayout.startAnimation(translate1);
// mProgressBar.setVisibility(View.VISIBLE);
mProgressDialog = ProgressDialog.show(Home.this, "",
"Loading...");
addWebView(mArrayListJBSelectedUrls.get(arg2)
.getStrSelectedWebsiteUrl().toString(), arg2);
}
});
/**
* on long press delete item from list view
*/
mListViewStar.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
position = arg2;
AlertDialog.Builder mAlert = new AlertDialog.Builder(Home.this);
mAlert.setTitle(getString(R.string.alert));
mAlert.setIcon(R.drawable.logo);
mAlert.setMessage(getString(R.string.delete_item_dialog));
mAlert.setPositiveButton(getString(R.string.yes),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
mDataBaseMethod.open();
Log.i("Delete", ""
+ mArrayListJBSelectedUrls
.get(position)
.getStrSelectedUrlId());
mDataBaseMethod
.deleteWebSites(mArrayListJBSelectedUrls
.get(position)
.getStrSelectedUrlId()
.toString());
mArrayListJBSelectedUrls.remove(position);
starBaseAdapter.notifyDataSetChanged();
mDataBaseMethod.close();
}
});
mAlert.setNegativeButton(getString(R.string.no),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
AlertDialog alertDialog = mAlert.create();
alertDialog.show();
return true;
}
});
推荐答案
add on onItemLongClick返回true
add return true on onItemLongClick
这篇关于同时使用setOnItemClickListener和setOnItemLongClickListener这两个侦听器会同时触发或同时触发.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!