ExpandableListView - OnChildTouchListener - android

I'm trying to create a drag-drop interface for a ExpandableListView.
I wanted to know if there is a function similar to OnChildClickListener for OnTouch?
If not, what would be the best way of listening for a touch event on a child inside the expandable list?

I realized we could add an OnTouchListener() in getChildView(). That would listen for a touch event every time the user touches the child item.

Related

android ListView touch-animation gone when onClickListener is attached

I have a ListView with a custom layout for the child items.
Without the OnClickListener attached to the items each item highlights nicely when the user touches it but as soon as I attach the listener the animation is gone. The listener is working but then there is no animation or visual feedback.
The same problem occurs when I use an OnTouchListener.
What can I do to grab the onClick-Event but still have the default animation?
With ListView you should use OnItemClickListener. If there's is a specific reason for using OnClickListener, you can manually fire the item click event. In your OnClickListener call performItemClick.

messing with touch / click events

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 except FINGER_UP event.
on FINGER_UP event, I execute the method which I initially had in onClickListener
public 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);
}
});
I'd like to add another clickListener to subview-group of the listView's row to handle click event on the subview.
You simply need to write a custom adapter and assign the OnClickListener in getView(). You can look at the question: Android GridView Button Click Handler for example code.
Also awhile back I answered Android. Scrolling 2 listviews together did you use a similar approach to synchronize your ListViews? When I combine both of the answers, my app functions the way you want. I hope this helps.

Dispatch events to child

I have a ListView containing items with one button each and I want to handle user events in this order:
TouchEvent on ListView.
TouchEvent on ListItem.
Click on Button inside ListItem.
How can I do this?
If understand correctly, with a single user click, you want to trigger the event (but not catch it) for each one of those items? You can't. I'd make either the list item or the button the clickable item, handle that, and do all of the logic you need to do in that handler.

ListView and propagating click events from children views in the items

I have a ListView with custom items - 3 ImageViews and a TextView. I have a call to setItemsCanFocus(true), so I can make the ImageViews clickable. I'm currently using SimpleAdapter to populate the View.
I'd like to trigger the AdapterView's onItemClick event when one of those subviews is clicked. The onItemClickListener receives a view as the second argument and that can be used to identify which subview was clicked. Frankly, I was expecting this to be the default behaviour but it isn't, unfortunately.
Is there any way to implement this behaviour without bluntly breaking encapsulation (i.e. creating an Adapter that holds a reference to its View)?
What is the accepted way of dealing with events from views in list items? How do you keep the Adapter from knowing too much about the ListView?
Unfortunately you have to choose between using onItemClick() or onClick() on individual children. One way to do it however is to make the top-level view of each item clickable.
Setting android:addStatesFromChildren="true" on the listview in your xml will send clicks on the child elements to the onItemClick method in the onItemClickListener connected to your listview.

Get click event and swipe gesture in imageswitcher in android?

I have an imageswitcher as the only component on the screen. I want to capture the swipe gesture and click event separately for it. But it is not able to get the events separately. If I set the onclicklistener method for imageswitcher object then it always fires onclick method even if I have swiped.
Can someone let me know the workaround to this?
If you return true from your onFling(…) it should consume the event and stop propagation.
Ref from this question:
android - giving onTouch priority over onClick

Categories

Resources