can ListView be inside ExpandableListView? - android

can we have ListView inside ExpandableListView so that I can have group level first and then array of child (listView). i already finish from listview classes and it works perfectly!
but how to call each group in expandable list view to display list view (layout)! and get the correct child !
please can any one help !
thanks.

Actually you can put a scrollable view (e.g. your ListView) inside another scrollable view (e.g. your ExpandableListView) and make the former scrollable in the following way:
listView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// disallow the onTouch for your scrollable parent view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

Yes you can! But the real thing is to create a listView in a expandableView.
Here is the trick: https://www.captechconsulting.com/blogs/android-expandablelistview-magic

Please take a look at this question which was asked two days ago. The user there was trying to put a custom view, derived from ListView into ExpandableListView. My answer to that question applies to your case as well, so I'll quote it:
You can't do that because you can't put a scrollable view(ListView)
into another scrollable view(ExpandableListView). The reason is that
the parent will consume all the touch events and they will never reach
the child. ExpandableListView will scroll, but the ListView will never
know that scrolling took place.

Related

ListFragment onListItemClick - how to know which component is clicked

The View Object is from onListItemClick(ListView listView, View view, int position, long id) is RelativeLayout.
However, I want to know which component inside the RelativeLayout is clicked as well for extended functionality.
How do I do that?
This answer show why use recyclerview instead of Listview, I think recyclerview will solve your problem stackoverflow.com/a/24933117/2242903
You have to add a listener to every view in RelativeLayout you want to listen. If you want to use a single listener, create one and add it to all of the views you want to listen. In your onClick method, you can put view.getId() to switch statement and determine which one is clicked.
OnItemClickListener won't solve your problem. Neither switching to RecyclerView. They work the same way. It is all about your adapter. If you are using a custom adapter, it doesn't matter you use ListView or RecyclerView. In your adapter, you have access to your components that are in your RelativeLayout. Create a listener as I explained above and add them to your views.
Not the same but similar question: Android: Add event listeners to every item in a ListView

Android ExpandableList Disable Groups

I have an expandable list with all groups always expanded and the groups not collapsable. The problem is that even if I made the groups to not collapse when I click on them the "select" effect is still visible and I don't want it to be visible. How can I do that?
Any answer would be appreciated.
Thanks
I have figure out myself after all how to do that :D I have put this code:
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event) {
return true;
}
});
in the adapter of the ExpandableList in the getGroupView method. And now it's working.
Normally when you click on the group name, it collapses automatically. Here is an example of expandableListView. Moreover, I could hardly make any comment unless I see what you did.

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.

Adapter for a List displayed inside a Scroll View, non-Scrolling List View?

In the app I am currently building I have been synchronizing ListViews with unbound Lists of data via BaseAdapter. This has been working so far but now I need to have a list of data inside a ScrollView. The problem with putting a ListView inside a ScrollView is that both views scroll and it make the activity difficult to navigate. From what I've read online the consensus seems to be that ListViews should never be put inside of scroll views for this reason, and that a LinearLayout or TableLayout should be used instead.
My quesion is this: Can any one tell me either how to get rid of the Scrolling Feature on a ListView or how to synchronize a List of data with a LinearLayout or a TableLayout through an adapter?
You could make your own custom ListView component and then override the dispatchTouchEvent() method:
#Override
public boolean dispatchTouchEvent(MotionEvent event)
{
int action = event.getAction();
if (!scrollEnabled) {
event.setAction(MotionEvent.ACTION_CANCEL);
super.dispatchTouchEvent(event);
return true;
}
return super.dispatchTouchEvent(event);
}
In these kinds of situations though, what I've done in the past is have a separate vertical LinearLayout for my list and manually added TextViews via code to it, making it look similar to a listview.

Items in ListView not long clickable after setting click listener in getView()

I've searched around and have not come out with a solution (maybe not using the correct keywords).
So, I've a custom ListView which its item can be dragged around when the item is long clicked. Within its item, there's an ImageView and LinearLayout containing two TextViews. Actions are done when the LinearLayout or ImageView is clicked.
To do this, I've use setOnItemLongClickListener on my DragListView which extends ListView, to initiate drag action, and onInterceptTouchEvent to manage the drag action.
Then, I have built a custom adapter extending BaseAdapter and overrided its getView() to implement the child items in the row. The LinearLayout and ImageView have been setOnClickListener.
The problem is, the LinearLayout and ImageView are able to do their stuff, but the onItemLongClick isn't called.
The listener inside getView();
holder.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//Do something
}
For item long click (drag initiator)
setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
//Do something
}
Thank you very much!
I think that a gesture detector is one of ways to handle events.
Usually, however, a gesture detector is used when we want to detect a gesture not a long-press.
The reason why onItemLongClick isn't called is that onClickListener might consume a touch event.
In that reason, if you want to handle onItemLongClick, intercept touch event and dispatch it to views you want to handle.
You can find more details following link.
http://developer.android.com/guide/topics/ui/ui-events.html
Ok, just found out the solution myself.
Instead of using onItemLongClickListener, I create a gesture detector to detect for long press. Then I override dispatchTouchEvent and force to scan for long press first, then return super.dispatchTouchEvent and the other following touch events.
Suggestions are still welcomed!

Categories

Resources