I am trying to implement the onItemLongClickListener
and onItemClickListener
events on a listview row, but the problem is that when I longPress the listview row and release it then both events get called at the same time. What would be the solution that achieves this.
Here is the code I am using.
listvideos.setLongClickable(true);
listvideos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int pos, long arg3) {
System.out.println("hh clickkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
if( lastLoded == TIMELINE || lastLoded == UPLOADS){
Intent i = new Intent(getActivity(), VideoStreamingActivity.class);
i.putExtra("clipname", videosVo.getInnerTopVideosVos().get(pos).getClipName());
i.putExtra("clipurl", videosVo.getInnerTopVideosVos().get(pos).getClipUrl());
i.putExtra("uploadername", videosVo.getInnerTopVideosVos().get(pos).getUploader_name());
i.putExtra("clipid", videosVo.getInnerTopVideosVos().get(pos).getClipId());
i.putExtra("rating", videosVo.getInnerTopVideosVos().get(pos).getRating());
i.putExtra("views", videosVo.getInnerTopVideosVos().get(pos).getTotalViews());
i.putExtra("thumburl", videosVo.getInnerTopVideosVos().get(pos).getThumbUrl());
adapterTopvideos.increaseViews(pos);
startActivity(i);
}
else if(lastLoded == PROFILE){
Intent i = new Intent(getActivity(), FriendProfileActivity.class);
i.putExtra("friendid", videosVo.getInnerFriendsVos().get(pos).getId());
i.putExtra("friendname", videosVo.getInnerFriendsVos().get(pos).getName());
ApplicationConstants.bmpFriend = videosVo.getInnerFriendsVos().get(pos).getImage();
startActivity(i);
}
}
});
listvideos.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
System.out.println("hh longgggggggggggggggggggggggggggg click");
// if(lastLoded == UPLOADS){
//
// if(!videosVo.getInnerTopVideosVos().get(pos).isChecked())
// videosVo.getInnerTopVideosVos().get(pos).setChecked(true);
// else
// videosVo.getInnerTopVideosVos().get(pos).setChecked(false);
//
// adapterTopvideos.notifyDataSetChanged();
// }
return false;
}
});
I found that the trick is in the return value of the longclick listener call back. If you return true, onclick will not be called after the longclick is called and simple click will invoke only on click. please try this one and let me know.
Put your
listvideos.setOnItemLongClickListener()
before yourlistvideos.setOnItemClickListener()
.That way when you long click on the item it will not perform the
onItemClickListener()
.Try this; it will work. I noticed that you are returning false in
listvideos.setOnItemLongClickListener
. Instead return true.Reason: Returning true after performing onItemLongClick prevents firing your onItemClick event after onItemLongClick. For example,
EDIT: Change your code as follows.
Your earlier code:
Change it to:
Try this: