Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpandableListView sample from Google

I just tried the current Google sample for ExpandableListiew:

This sample seem very simple and easy to use, but what I would like to do is to say that one of the category has no child. I removed all the children but the problem is that the arrow still appears on this current line.

For instance, imagine that I remove all "Cat Names", the arrow is still there and when I click on it, the arrow just change. How to remove this arrow and launch an activity instead?

like image 734
Waza_Be Avatar asked Aug 14 '10 14:08

Waza_Be


People also ask

How do you get a child position in ExpandableListView?

You have to use Adapter's getChild(groupPosition, childPosition) method to retrieve the instance of child.

What is ExpandableListView in Android?

android.widget.ExpandableListView. A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view.


2 Answers

If you're talking about the arrow that is used to collapse/expand the list then you can remove it by using setGroupIndicator()

in the activity you can call

getExpandableListView().setGroupIndicator(null);

that will remove the arrow permanently though. If you want to only hide it if the list is empty you can do it through xml attributes like this

To launch an activity when the list is expanded/collapsed you can override onGroupExpanded (or collapsed) in your ListAdapter implementation and used that to fire up your activity

like image 129
FearlessHyena Avatar answered Nov 09 '22 01:11

FearlessHyena


In general, if you want a specific area of your activity to be refreshed when you come back from another activity; you got to write in the onResume() method.

Steps: 1 – In the Activity you want it to be refreshed, override the onResume() method:

@Override
protected void onResume() {
    super.onResume();
    // TODO: PUT YOUR REFRESH CODE IN HERE
}

2- You will need to refresh your Expandable Adapter.

I suggest you take the same code you used to instantiate your expandable list and put it again, like follows:

SimpleExpandableListAdapter expandableListAdapter =
    new SimpleExpandableListAdapter(
        this,
        YourPrentsList, // List of your parent 
        R.layout.parents_layout,    // Layout for the Parents
        new String[] { "groupKey" },    // Key in the Group Data maps to display
        new int[] { 1 },        
        childrenList,   // List of the children
        R.layout.childs_layout, // Layout of the children
        new String[] { "keys"}, 
        new int[] { 1}  
    );
setListAdapter( expandableListAdapter );

I hope this solves your concern... Thanks,

Mohamed.

like image 23
Mohamed A.Karim Avatar answered Nov 09 '22 00:11

Mohamed A.Karim