Android - Expandablelistview

clear ExpandableListView

Have you tried inputting an empty adapter? Something like the following:

ExpandableListAdapter adapter = new ExpandableListAdapter(); //or what ever adapter you use/created
listView.setAdapter(adapter);

This is not a null adapter and you will not get a null pointer. The adapter will contain no elements to display/show/populate.

You can check if the adapter is empty by calling isEmpty().

Android ExpandableListView : set background color of selected item on click

At first remove attribute:

 <ExpandableListView
android:listSelector = "@drawable/selector_categorie_item" />

and also remove background selector from ExpandableListView.

Then in your child layout item put next attribute:

 <YourLayout
android:background = "@drawable/your_selector" />

Maybe you need the selector like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="true"
android:state_pressed="true" android:drawable="@drawable/exp_list_item_bg_pressed" />
<item android:state_enabled="true"
android:state_focused="true" android:drawable="@drawable/exp_list_item_bg_focused" />
<item android:state_enabled="true"
android:state_selected="true" android:drawable="@drawable/exp_list_item_bg_focused" />
<item
android:drawable="@drawable/exp_list_item_bg_normal" />
</selector>

Put on the right the indicator of an ExpandableListView in Android

I don't know a way to do that from XML but i'll tell you a way to do so dynamically in your adapter.

First you have to remove group indicator from your xml

 <ExpandableListView [...] 
android:groupIndicator="@null" />

Then in your layout of the parent add an imageview in the right position of your layout.

Then in your custom adapter do the following

public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
...

if (isExpanded) {
groupHolder.img.setImageResource(R.drawable.group_down);
} else {
groupHolder.img.setImageResource(R.drawable.group_up);
}
...

}

ExpandableListView - collapse groups automatically

listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
YourExpandableListAdapter customExpandAdapter = (YourExpandableListAdapter)listView.getExpandableListAdapter();
if (customExpandAdapter == null) {return;}
for (int i = 0; i < customExpandAdapter.getGroupCount(); i++) {
if (i != groupPosition) {
listView.collapseGroup(i);
}
}
}
});

Android ExpandableListView - Looking for a tutorial

you can find working example of the expandable list view by following links:

  • ExpandableListView

  • Expandable ListView in ANDROID

  • Android Expandable ListView simple Example in android.

for click on child, you can handle this way.

getExpandableListView().setOnChildClickListener(new OnChildClickListener() {                
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// your code...
}
});

Hope this will help you.
Thanks..

Only one group will expand in ExpandableListView

You may achieve using GroupExpandListener.Store last Expanded position to variable and collapseGroup using this variable

private int lastPosition = -1;
private ExpandableListView lv; //your expandable listview

lv.setOnGroupExpandListener(new OnGroupExpandListener() {

@Override
public void onGroupExpand(int groupPosition) {
if (lastPosition != -1
&& groupPosition != lastPosition) {
lv.collapseGroup(lastPosition);
}
lastPosition = groupPosition;
}
});


Related Topics



Leave a reply



Submit