I am using Exapandable listview inside a fragment,i am passing 8 values but it is showing only 6 values and that too the exapnadable listview is not scrolling.the same if i put it in activity..everything works fine.but when i use within fragment it is showing error.can anyone tell me how to solve it...here is my code
public class GroupsFragment extends Fragment {
View groupview;
List<String> tdp, congress, ysrcp, bjp;
ExpandableListView expandableListView;
HashMap<String, ArrayList<GroupModel>> expandableListDetail;
ArrayList<GroupModel> contacts;
List<String> expandableListTitle;
ExpandableListAdapter expandableListAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the dailog_layout for this fragment
groupview = inflater.inflate(R.layout.contacts_expandable_list, container, false);
expandableListView = groupview.findViewById(R.id.expanded_list_view_contacts);
contacts = new ArrayList<>();
return groupview;
}
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
expandableListDetail = new HashMap<String, ArrayList<GroupModel>>();
showContactsList();
}
#SuppressLint("ClickableViewAccessibility")
private void showContactsList() {
getExpandableListItems();
expandableListTitle = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new CustomContactsExapandableListAdapter(getActivity(), expandableListTitle, expandableListDetail);
expandableListView.setAdapter(expandableListAdapter);
}
private HashMap<String, ArrayList<GroupModel>> getExpandableListItems() {
contacts.add(new GroupModel("gopi", "Officer", "9999999999", "abcd0"));
expandableListDetail.put("TDP", contacts);
expandableListDetail.put("YSRCP", contacts);
expandableListDetail.put("Congress", contacts);
expandableListDetail.put("BJP", contacts);
expandableListDetail.put("ABC", contacts);
expandableListDetail.put("CDE", contacts);
expandableListDetail.put("DEF", contacts);
expandableListDetail.put("FED", contacts);
return expandableListDetail;
}
}
and here is the adapter
public class CustomContactsExapandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> expandableListTitle;
private HashMap<String, ArrayList<GroupModel>> expandableListDetail;
public CustomContactsExapandableListAdapter(Context context, List<String> expandableListTitle,
HashMap<String, ArrayList<GroupModel>> expandableListDetail) {
this.context = context;
this.expandableListTitle = expandableListTitle;
this.expandableListDetail = expandableListDetail;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return this.expandableListDetail.get(this.expandableListTitle.get(groupPosition))
.get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
Log.i("test", "the value in exapandable is " + getChild(groupPosition, childPosition));
final GroupModel expandedListText = (GroupModel) getChild(groupPosition, childPosition);
Log.i("test", "the text is " + expandedListText.getName()+ " "+ expandedListText.getDesignation() + " " +expandedListText.getMobile() );
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.single_contact, null);
}
TextView expandedListTextViewName = (TextView) convertView
.findViewById(R.id.contact_name);
TextView expandedListTextViewMobile = (TextView) convertView
.findViewById(R.id.contact_mobile_num);
expandedListTextViewMobile.setText(expandedListText.getDesignation());
expandedListTextViewName.setText(expandedListText.getName());
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this.expandableListDetail.get(this.expandableListTitle.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
return this.expandableListTitle.get(groupPosition);
}
#Override
public int getGroupCount() {
Log.i("test", "the value in exapandable group is " + expandableListTitle.size());
return expandableListTitle.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String listTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.single_party, null);
}
TextView listTitleTextView = (TextView) convertView
.findViewById(R.id.party_name);
ImageView imageView=convertView.findViewById(R.id.party_expandable_image);
if(isExpanded){
imageView.setImageResource(R.drawable.minus_icon_contacts);
}
else {
imageView.setImageResource(R.drawable.plus_icon_contacts);
}
listTitleTextView.setTypeface(null, Typeface.BOLD);
listTitleTextView.setText(listTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Related
I have an ExpandableListView which is populated using data coming from serverside(reftrofit) how can I use an Adapter to get a specific element of the object? The expandable list view contains parent and child elements. When I click on the child element I would like to extract an ID(SensorID) that is associated with that child element.
I Have an Adapterwhere I am attempting to extract the ID from the object but I am unable to. I noticed that for an array Adapterthe getItemAtPosition() method is used to get an index then extract an element from the object(sensorID).
I am however not sure if this is the same method that should be used for an ExpandableListAdapter because I have seen snippets of code where the method getChild() is used.
The error I get everytime on click reads
ExpandableListConnector cannot be cast to
com.xera.deviceinsight.home.ExpandableListAdapter
The method in question
private void load(View view)
{
expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
prepareListData();
listAdapter = new ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
System.err.println("child clicked");
Toast.makeText(getActivity(), "child clicked", Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new ItemClickedEvent(SensorInformationChildFragment.TAB_CALL));
ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();
OrganisationDeviceSensorsResult deviceSensor = (OrganisationDeviceSensorsResult) adapter.getChild(groupPosition , childPosition);
sensorID = deviceSensor.SensorID;
ReportingGroup.get(childPosition);
return true;
}
});
}
Adapter:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public List<OrganisationDeviceSensorsResult> Items;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public OrganisationDeviceSensorsResult getItemAtPosition(int index)
{
return getItemAtPosition(index);
//return this.getItem(index);
//return this.getItem(index);
//return index;
//return this.get
//return OrganisationDeviceSensorsResult.
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
OrganisationDeviceSensorsResult deviceSensor = getItemAtPosition(childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
#Override
public int getGroupCount() {
return this._listDataHeader.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
I had more or less your situation, I do it with this code in the Activity where the listview is placed:
contactListExpandable = (ExpandableListView) findViewById(R.id.contactlist);
contactListAdapter = new ContactListAdapter(this, chatGroupList);
contactListExpandable.setAdapter(contactListAdapter);
contactListExpandable.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
ChatContact contact = chatGroupList.get(groupPosition).getContacts().get(childPosition);
launchChat(contact, null, false, "");
return false;
}
});
In my case, I get the child Object to launch a chat, etc, in your case you will be abre to obtain the Sensor object and do your stuff
=== ChatGroup ===
public class ChatGroup implements Comparable{
final public String name;
private List<ChatContact> contacts;
public ChatGroup(String name){
this.name = name;
this.contacts = new ArrayList<>();
}
public void addContact(ChatContact contact){
this.contacts.add(contact);
}
public List<ChatContact> getContacts(){
return this.contacts;
}
#Override
public int compareTo(Object o) {
ChatGroup cg = (ChatGroup)o;
return name.compareTo(cg.name);
}
}
=== ChatContact.java ===
public class ChatContact implements Parcelable, Comparable {
final public String name;
final public String jid;
public Status status;
public ChatContact(String name, String jid) {
this.name = name;
this.jid = jid;
}
.....getters/setters/etc.....
}
After reading data from a CSV file, I have it stored in List.
List <String>listDataHeader = new ArrayList<String>();
Map<String,String>listDataChild = new HashMap<String, String>();
List<String[]> termDefinition = csv.read();
Then I itirate over the list and want to store the data. As it is written now, I take the correct keys, but not the values:
for (String[] term : termDefinition) {
listDataHeader.add(term[0]);
listDataChild.put(term[0], term[1]);
}
May you help me? Thanks!
EDIT:
I need to fill data in ExpandavbleListVew. The listdataHeader is the main topic, the listdataChild is the subitem. There are only 2 columns in the CSV, in the format term-definition. At the moment, main topics (from the listDataheader) are stored correctly. After correcting the loop (see above), I have for each main item the definition appearing as many times as the size of the loop (10 in the case).
Here is the expandableListView class:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listDataHeader; // header titles
// child data in format of header title, child title
private Map<String, String> listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
Map<String, String> listChildData) {
this.context = context;
this.listDataHeader = listDataHeader;
this.listDataChild = listChildData;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this.listDataChild.get(this.listDataHeader.get(groupPosition));
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.itemList);
txtListChild.setText(childText);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this.listDataChild.size();
}
#Override
public Object getGroup(int groupPosition) {
return this.listDataHeader.get(groupPosition);
}
#Override
public int getGroupCount() {
return this.listDataHeader.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.header, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.headerList);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
I don't see the point of the listDataHeader List. Using it causes you to put the same key (listDataHeader.get(0)) over and over again in the Map.
Since you only have 2 columns in each row of the CSV, all you need is :
for (String[] term : termDefinition) {
listDataChild.put(term[0], term[1]);
}
My Fragment didn't show anything for my expandable view. there's not error as well. and i don't know where went wrong so i need help Can someone let me know my error? There's no error on the page/didn't have any crashes as well
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listGroup;
private HashMap<String, List<String>> listChild;
public MyExpandableListAdapter(Context context, List<String> listGroup,
HashMap<String, List<String>> listChild) {
this.context = context;
this.listGroup = listGroup;
this.listChild = listChild;
}
#Override
public int getGroupCount() {
return listGroup.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return listChild.get(listGroup.get(groupPosition)).size();
}
#Override
public Object getGroup(int groupPosition) {
return listGroup.get(groupPosition);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return listChild.get(listGroup.get(groupPosition)).get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_layout, null);
}
String textGroup = (String) getGroup(groupPosition);
TextView textViewGroup = (TextView) convertView
.findViewById(R.id.group);
textViewGroup.setText(textGroup);
return convertView;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.item_layout, null);
}
TextView textViewItem = (TextView) convertView.findViewById(R.id.item);
String text = (String) getChild(groupPosition, childPosition);
textViewItem.setText(text);
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}
public class Hotel extends Fragment {
ExpandableListView expandableListView;
MyExpandableListAdapter myExpandableListAdapter;
List<String> groupList;
HashMap<String, List<String>> childMap;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.hotel_frag, container, false);
init();
expandableListView = (ExpandableListView) v.findViewById(R.id.mylist);
expandableListView.setAdapter(myExpandableListAdapter);
myExpandableListAdapter = new MyExpandableListAdapter(Hotel.this.getActivity().getApplicationContext(), groupList, childMap);
return v;
}
private void init() {
groupList = new ArrayList<String>();
childMap = new HashMap<String, List<String>>();
List<String> groupList0 = new ArrayList<String>();
groupList0.add("groupList0 - 1");
groupList0.add("groupList0 - 2");
groupList0.add("groupList0 - 3");
List<String> groupList1 = new ArrayList<String>();
groupList1.add("groupList1 - 1");
groupList1.add("groupList1 - 2");
groupList1.add("groupList1 - 3");
List<String> groupList2 = new ArrayList<String>();
groupList2.add("groupList2 - 1");
groupList2.add("groupList2 - 2");
groupList2.add("groupList2 - 3");
List<String> groupList3 = new ArrayList<String>();
groupList3.add("groupList3 - 1");
groupList3.add("groupList3 - 2");
groupList3.add("groupList3 - 3");
groupList.add("Group List 0");
groupList.add("Group List 1");
groupList.add("Group List 2");
groupList.add("Group List 3");
childMap.put(groupList.get(0), groupList0);
childMap.put(groupList.get(1), groupList1);
childMap.put(groupList.get(2), groupList2);
childMap.put(groupList.get(3), groupList3);
}
}
http://i.stack.imgur.com/dnM7Q.png
http://i.stack.imgur.com/eXJOz.png
http://i.stack.imgur.com/VmaUj.png
You have to construct the adapter before you assign it to the ListView:
init();
myExpandableListAdapter = new MyExpandableListAdapter(Hotel.this.getActivity().getApplicationContext(), groupList, childMap);
expandableListView = (ExpandableListView) v.findViewById(R.id.mylist);
expandableListView.setAdapter(myExpandableListAdapter);
I am writing an Android application that is utilizing the ExpandableListView feature, and for some reason, I can't seem to get the view to populate. I was originally using a regular ListView, one which populated with the correct information. I then refactored the code to utilize the ExpandableListView. Here are all relevant snippets from my project:
SeasonsFragment.java (Which is called properly in MainActivity)
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
ArrayList<Season> seasons = ((App)getActivity().getApplication()).getSeasonsList();
ArrayList<RowItem> rowItems = new ArrayList<>();
for (int i = 0; i < seasons.size(); i++) {
RowItem items = new RowItem(seasons.get(i));
rowItems.add(items);
}
CustomAdapter adapter = new CustomAdapter(getActivity(), rowItems);
View rootView = inflater.inflate(R.layout.seasons_fragment, container, false);
ExpandableListView list_view = (ExpandableListView) rootView.findViewById(R.id.list);
list_view.setAdapter(adapter);
return inflater.inflate(R.layout.seasons_fragment, container, false);
}
CustomAdapter.java
public class CustomAdapter extends BaseExpandableListAdapter {
Context context;
List<RowItem> rowItem;
private HashMap<String, List<Sport>> listDataChildren = new HashMap<>();
public CustomAdapter(Context context, List<RowItem> rowItem) {
Log.i("Custom Adapter", "Created");
this.context = context;
this.rowItem = rowItem;
for (RowItem item : rowItem){
Season season = item.getSeason();
listDataChildren.put(item.getText(), season.getSports());
}
}
#Override
public int getGroupCount() {
return rowItem.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return listDataChildren.get(rowItem.get(groupPosition)).size();
}
#Override
public Object getGroup(int groupPosition) {
return rowItem.get(groupPosition);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return listDataChildren.get(rowItem.get(groupPosition)).get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
Log.i("Group ID", "Getting group ID");
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
Log.i("Group View", "Group view called");
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.row_item, null);
}
final RowItem row_pos = rowItem.get(groupPosition);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
txtTitle.setText(row_pos.getText());
Button button = (Button) convertView.findViewById(R.id.button); //TODO: Check memory for subscription status
if (row_pos.isSubscribed()){
row_pos.setSubscribed(false);
button.setBackgroundResource(R.drawable.checkmark3);
} else {
row_pos.setSubscribed(true);
button.setBackgroundResource(R.drawable.ic_add_black_24dp);
}
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {/*
if (item.isSubscribed()){
item.setSubscribed(false); //TODO: This isn't working properly.
v.setBackgroundResource(R.drawable.checkmark3);
} else {
item.setSubscribed(true);
v.setBackgroundResource(R.drawable.ic_add_black_24dp);
}*/
}
});
return convertView;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText("TEST");
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
All Layout XMLs were inflated properly in the ListView, but nothing is inflating in the ExpandableListView. The method getGroupView isn't even being called. Any help would be appreciated.
Change
return inflater.inflate(R.layout.seasons_fragment, container, false);
to
return rootView;
i want to create groups and childs in expandable listview from json in android?.how to add the json data to expandable listview group and child item
You can use custom adapter class to create expandable list view. Create a new class file called ExpandableListAdapter.java and extend this from BaseExpandableListAdapter. This class provides required methods to render such listview.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
#Override
public int getGroupCount() {
return this._listDataHeader.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Follow this link: http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/