This doesn't seem like a typical view layout which I'm having trouble with.
I have two listViews.
Each listView
has touchListener
(whose purpose is to synchronize scrolling by calling dispatchTouchEvent() to another listView)
ListView
also has onItemClickListener
to handle clicks on the row of listView.
Everything works as intended up to here.
I'd like to add another clickListener
to subview-group of the listView's
row to handle click event on the subview.
After attaching this clickListener, I see listView's scroll doesn't always work.
I suspect its because the clickListener of this child view is inspecting touch events (to see if its indeed a click
) before the parent(listView)'s touchListener.
I can think of two workarounds to this problem.
attach touchListener instead of clickListener to child, and make it
return false
for all touch event exceptFINGER_UP
event.
onFINGER_UP
event, I execute the method which I initially had in onClickListenerpublic boolean onInterceptTouchEvent (MotionEvent ev)
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.
(ok... I'm confused, I thought touch events goes to child views first and propagate to parents if children don't handle the touches..)
.. How do I implement the method 1?
.. Please help me to figure out #2 as well and to grasp the touch delivery mechanism.
EDIT - This is where I add OnClickListener to my subview.
viewHolder.layout_author.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent profileIntent = new Intent(ImageListAdapter.this.activity, ProfileActivity.class); profileIntent.putExtra("JsonUser", jsonAlbumImage.jsonUser); ImageListAdapter.this.activity.startActivity(profileIntent); } });