My activity implements OnTouchListener and it have one ListView inside it.
When user touch over ListView, I need to dispatch ClickEvent to ListView that has OnItemClickListener handler.
How can I do this?
edit:
Each list item of listView have onTouchEvent handler.
ListView have onItemClick handler.
@Override
public boolean onTouch(View view, MotionEvent event) {
float actionUpX;
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
actionDownX = event.getX();
break;
case MotionEvent.ACTION_UP:
actionUpX = event.getX();
mFlipper = (ViewFlipper) view.findViewById(R.id.view_listitem_flipper);
if(actionDownX < actionUpX){
// |--->
mFlipper.showNext();
} else if(actionDownX > actionUpX){
// <---|
mFlipper.showPrevious();
} else {
//Click
//Need to dispatch itemClickEvent to ListView
//view.performClick(); this line causes StackOverflowException
}
break;
}
return true;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//Need do an action using position of view
}
My list item is a ViewFlipper, when user touch and drag item, ViewFlipper need perform
showNext or ShowPrevious and an single click have to handled by onItemClick
If you want to be able to click on an item in the list and have something happen you need to do something like the following:
You will also need an adapter class (in my example my adapter class is called
YourAdapterClass) You can either make this a private class in your ListActivty or a completely new class in its own Java file like the following:Usually this way is used for custom ListViews (lists with custom made rows, but you can use it for a normal view as well)
Hope this helps you at least get started in the right direction.
Good Luck.
(this was an answer I basically gave for another thread similar to this one Custom ListVIew and onclick)