I am trying to restore a child when a user clicked on a child of an ExpandableListView. To do this, my Activity and ListAdapter classes are as follows.
MainActivity: -
public class MainActivity extends Activity { NewAdapter mNewAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ExpandableListView expandbleLis = (ExpandableListView) findViewById(R.id.expandableListView); expandbleLis.setDividerHeight(2); expandbleLis.setGroupIndicator(null); expandbleLis.setClickable(true); setGroupData(); setChildGroupData(); mNewAdapter = new NewAdapter(groupItem, childItem); mNewAdapter .setInflater( (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this); expandbleLis.setAdapter(mNewAdapter); expandbleLis.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { Toast.makeText(MainActivity.this, "GroupItem Clicked" + groupItem.get(groupPosition), Toast.LENGTH_LONG).show(); return false; } }); expandbleLis.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Toast.makeText(MainActivity.this, "ChildItem Clicked", Toast.LENGTH_LONG).show(); return false; } }); } public void setGroupData() { groupItem.add("TechNology"); groupItem.add("Mobile"); groupItem.add("Manufacturer"); groupItem.add("Extras"); } ArrayList<String> groupItem = new ArrayList<String>(); ArrayList<Object> childItem = new ArrayList<Object>(); public void setChildGroupData() { ArrayList<String> child = new ArrayList<String>(); child.add("Java"); child.add("Drupal"); child.add(".Net Framework"); child.add("PHP"); childItem.add(child); child = new ArrayList<String>(); child.add("Android"); child.add("Window Mobile"); child.add("iPHone"); child.add("Blackberry"); childItem.add(child); child = new ArrayList<String>(); child.add("HTC"); child.add("Apple"); child.add("Samsung"); child.add("Nokia"); childItem.add(child); child = new ArrayList<String>(); child.add("Contact Us"); child.add("About Us"); child.add("Location"); child.add("Root Cause"); childItem.add(child); } }
ListAdapter: -
public class NewAdapter extends BaseExpandableListAdapter { public ArrayList<String> groupItem, tempChild; public ArrayList<Object> Childtem = new ArrayList<Object>(); public LayoutInflater minflater; public Activity activity; public NewAdapter(ArrayList<String> grList, ArrayList<Object> childItem) { groupItem = grList; this.Childtem = childItem; } public void setInflater(LayoutInflater mInflater, Activity act) { this.minflater = mInflater; activity = act; } @Override public Object getChild(int groupPosition, int childPosition) { return null; } @Override public long getChildId(int groupPosition, int childPosition) { return 0; } @Override public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { tempChild = (ArrayList<String>) Childtem.get(groupPosition); TextView text = null; if (convertView == null) { convertView = minflater.inflate(R.layout.childrow, null); } text = (TextView) convertView.findViewById(R.id.textView1); text.setText(tempChild.get(childPosition)); return convertView; } @Override public int getChildrenCount(int groupPosition) { return ((ArrayList<String>) Childtem.get(groupPosition)).size(); } @Override public Object getGroup(int groupPosition) { return null; } @Override public int getGroupCount() { return groupItem.size(); } @Override public void onGroupCollapsed(int groupPosition) { super.onGroupCollapsed(groupPosition); } @Override public void onGroupExpanded(int groupPosition) { super.onGroupExpanded(groupPosition); } @Override public long getGroupId(int groupPosition) { return 0; } @Override public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
Googled tried this from me, but didnβt use it, I donβt get a child from it. please help with this.
Having tried many possible solutions, I am posting this, please try to help me do not vote, if you vote, tell me a possible solution, then I will agree.