-
-
Save bowmanb/4052030 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent"> | |
<ExpandableListView android:id="@+id/list" | |
android:layout_height="match_parent" | |
android:layout_width="match_parent" /> | |
</LinearLayout> |
package com.advinture.ukuleletabs.fragments; | |
import android.app.ExpandableListActivity; | |
import android.app.Fragment; | |
import android.os.Bundle; | |
import android.view.Gravity; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.AbsListView; | |
import android.widget.BaseExpandableListAdapter; | |
import android.widget.ExpandableListView; | |
import android.widget.TextView; | |
import com.advinture.ukuleletabs.R; | |
/** | |
* Pieced together from: | |
* Android samples: com.example.android.apis.view.ExpandableList1 | |
* http://androidword.blogspot.com/2012/01/how-to-use-expandablelistview.html | |
* http://stackoverflow.com/questions/6938560/android-fragments-setcontentview-alternative | |
* http://stackoverflow.com/questions/6495898/findviewbyid-in-fragment-android | |
*/ | |
public class SavedTabsFragment extends Fragment { | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View v = inflater.inflate(R.layout.saved_tabs, null); | |
ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.list); | |
elv.setAdapter(new SavedTabsListAdapter()); | |
return v; | |
} | |
public class SavedTabsListAdapter extends BaseExpandableListAdapter { | |
private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" }; | |
private String[][] children = { | |
{ "Arnold", "Barry", "Chuck", "David" }, | |
{ "Ace", "Bandit", "Cha-Cha", "Deuce" }, | |
{ "Fluffy", "Snuggles" }, | |
{ "Goldy", "Bubbles" } | |
}; | |
@Override | |
public int getGroupCount() { | |
return groups.length; | |
} | |
@Override | |
public int getChildrenCount(int i) { | |
return children[i].length; | |
} | |
@Override | |
public Object getGroup(int i) { | |
return groups[i]; | |
} | |
@Override | |
public Object getChild(int i, int i1) { | |
return children[i][i1]; | |
} | |
@Override | |
public long getGroupId(int i) { | |
return i; | |
} | |
@Override | |
public long getChildId(int i, int i1) { | |
return i1; | |
} | |
@Override | |
public boolean hasStableIds() { | |
return true; | |
} | |
@Override | |
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { | |
TextView textView = new TextView(SavedTabsFragment.this.getActivity()); | |
textView.setText(getGroup(i).toString()); | |
return textView; | |
} | |
@Override | |
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) { | |
TextView textView = new TextView(SavedTabsFragment.this.getActivity()); | |
textView.setText(getChild(i, i1).toString()); | |
return textView; | |
} | |
@Override | |
public boolean isChildSelectable(int i, int i1) { | |
return true; | |
} | |
} | |
} |
Thanks a lot... :)
thanks a lot
Save my day, thanks a lot!!!
thanks alot,,,,,,,,,,,,,,
Please help me ..i'm getting "classcast exception"
how to set image to the above ex_listview???
Saved me. Thanks alot!
Still wondering how do you format the style and text for this very handy expandable list.
Or how to use an inflater from another xml files. Thanks in advance.
you can pass the context in the constructor for SavedTabsListAdapter and then inflate the custom xml layout for group and child views.
thank u. you have saved my design, i was stack for so a long period of time before founding this code.
Sir , how can i use OnClickListners on the sub items of list to open a new activity.
This is awesome and super concise, thanks you so much!
Please give an example for how to inflate custom layout for group header and items ?
Thanks. This is working
thanks a lott....its working very fine
thankyou
Thanks!! :)