title: Android Mulitilevel listview or expandble listview
body: <p>I'm using multi level <code>ExpandableListView</code> in that how to achieve 3 level <code>Listview</code> please  give some reference.</p>
  
  <p><a href="https://i.stack.imgur.com/Poxsf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Poxsf.png" alt="enter image description here"></a></p>
  
  <p>I have added 2 levels but couldn't manage to add 3rd level child element with in 2nd level <code>ExpandableListView</code>  child element.</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener
  {
  
      private LinkedHashMap&lt;String, Header&gt; myDepartments = new LinkedHashMap&lt;String, Header&gt;();
      private ArrayList&lt;Header&gt; deptList = new ArrayList&lt;Header&gt;();
  
      private ListAdapter listAdapter;
      private ExpandableListView myList;
      List&lt;String&gt; li;
      EditText et;
      Spinner spinner;
  
      @Override
  
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          spinner = (Spinner) findViewById(R.id.department);
          li=new ArrayList&lt;String&gt;();
          Button b=(Button) findViewById(R.id.add1);
          et=(EditText)findViewById(R.id.product1);
          b.setOnClickListener(new View.OnClickListener()
          {
             public void onClick(View v)
             {
                  // TODO Auto-generated method stub
  
                  li.add(et.getText().toString());
                  et.setText(null);
                  add();
              }
          });
  
          add();
  
  
  
          myList = (ExpandableListView) findViewById(R.id.myList);
          listAdapter = new ListAdapter(MainActivity.this, deptList);
          myList.setAdapter(listAdapter);
          expandAll();
          Button add = (Button) findViewById(R.id.add);
          add.setOnClickListener(this);
          myList.setOnChildClickListener(myListItemClicked);
          myList.setOnGroupClickListener(myListGroupClicked);
      }
  
      private void add()
      {
          ArrayAdapter&lt;String&gt; adp=new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_dropdown_item_1line,li);
          spinner.setAdapter(adp);
      }
  
  
      public void onClick(View v)
      {
  
          switch (v.getId())
          {
  
              //add entry to the List
              case R.id.add:
  
                  Spinner spinner = (Spinner) findViewById(R.id.department);
                  String department = spinner.getSelectedItem().toString();
                  EditText editText = (EditText) findViewById(R.id.product);
                  String product = editText.getText().toString();
                  editText.setText("");
                  int groupPosition = addProduct(department,product);
                  listAdapter.notifyDataSetChanged();
                  collapseAll();
                  myList.expandGroup(groupPosition);
                  myList.setSelectedGroup(groupPosition);
                break;
  
          }
      }
  
  
      //method to expand all groups
      private void expandAll() {
          int count = listAdapter.getGroupCount();
          for (int i = 0; i &lt; count; i++){
              myList.expandGroup(i);
          }
      }
  
      //method to collapse all groups
      private void collapseAll() {
          int count = listAdapter.getGroupCount();
          for (int i = 0; i &lt; count; i++){
              myList.collapseGroup(i);
          }
      }
  
  
      //our child listener
      private OnChildClickListener myListItemClicked =  new OnChildClickListener() {
  
          public boolean onChildClick(ExpandableListView parent, View v,
                                      int groupPosition, int childPosition, long id) {
  
              //get the group header
              Header headerInfo = deptList.get(groupPosition);
              //get the child info
              Detail detailInfo =  headerInfo.getProductList().get(childPosition);
              //display it or do something with it
              Toast.makeText(getBaseContext(), "Clicked on Detail " + headerInfo.getName()
                      + "/" + detailInfo.getName(), Toast.LENGTH_LONG).show();
              return false;
          }
  
      };
  
      //our group listener
      private OnGroupClickListener myListGroupClicked =  new OnGroupClickListener()
      {
  
          public boolean onGroupClick(ExpandableListView parent, View v,
                                      int groupPosition, long id) {
  
              //get the group header
              Header headerInfo = deptList.get(groupPosition);
              //display it or do something with it
              Toast.makeText(getBaseContext(), "Child on Header " + headerInfo.getName(),
                      Toast.LENGTH_LONG).show();
  
              return false;
          }
  
      };
  
      private int addProduct(String department, String product){
  
          int groupPosition = 0;
  
          //check the hash map if the group already exists
          Header headerInfo = myDepartments.get(department);
          //add the group if doesn't exists
          if(headerInfo == null){
              headerInfo = new Header();
              headerInfo.setName(department);
              myDepartments.put(department, headerInfo);
              deptList.add(headerInfo);
          }
  
          //get the children for the group
          ArrayList&lt;Detail&gt; productList = headerInfo.getProductList();
          //size of the children list
          int listSize = productList.size();
          //add to the counter
          listSize++;
  
          //create a new child and add that to the group
          Detail detailInfo = new Detail();
          detailInfo.setSequence(String.valueOf(listSize));
          detailInfo.setName(product);
          productList.add(detailInfo);
          headerInfo.setProductList(productList);
  
          //find the group position inside the list
          groupPosition = deptList.indexOf(headerInfo);
          return groupPosition;
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  }
  </code></pre>