title: How to make dynamic expandable listview?
body: <p>I am making a dynamic Expandable listview in which i want to show its title in header(Parent) and other value inside Parent that means on Child. I am able to get value from Server and want to show that values in Expandable listview. I am able to set Names in Header but I am not able to show other values in child , How should i do this please help me.</p>
  
  <p>I am following <a href="http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/" rel="nofollow noreferrer">this tutorial</a> </p>
  
  <p>This is the code in Activity</p>
  
  <pre><code>public class Pxe extends Activity {
  
      ExpandableListAdapter listAdapter;
      ExpandableListView expListView;
      List&lt;String&gt; listDataHeader;
      HashMap&lt;String, List&lt;String&gt;&gt; listDataChild;
      String myJSON,company_name,from_date,to_date,location,fire_id,guard_number;
      JSONArray peoples = null;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.ex_main);
  
          // get the listview
          expListView = (ExpandableListView) findViewById(R.id.lvExp);
  
          // preparing list data
         // prepareListData();
          getProp();
  
      }
  
  
  
  
      public void getProp(){
          class GetDataJSON extends AsyncTask&lt;String, Void, String&gt; {
              public void onPreExecute() {
                  // Pbar.setVisibility(View.VISIBLE);
              }
              @Override
              protected String doInBackground(String... params) {
  
                  InputStream inputStream = null;
                  String result = null;
                  try {
  
                      URL url = new URL("http://xxxxxxxxx/app/guard/guard_history.php");
                      JSONObject postDataParams = new JSONObject();
                      Log.e("Value&gt;&gt;&gt;&gt;&gt;", String.valueOf(postDataParams));
                      postDataParams.put("guard_id", "1");
                      Log.e("params", postDataParams.toString());
  
                      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                      conn.setReadTimeout(15000 /* milliseconds */);
                      conn.setConnectTimeout(15000 /* milliseconds */);
                      conn.setRequestMethod("POST");
                      conn.setDoInput(true);
                      conn.setDoOutput(true);
                      OutputStream os = conn.getOutputStream();
                      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                      writer.write(getPostDataString(postDataParams));
  
                      writer.flush();
                      writer.close();
                      os.close();
  
                      int responseCode=conn.getResponseCode();
  
                      if (responseCode == HttpsURLConnection.HTTP_OK) {
  
                          BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
                          StringBuilder sb = new StringBuilder("");
                          String line="";
                          while ((line = in.readLine()) != null)
                          {
                              sb.append(line).append("\n");
                          }
                          result = sb.toString();
                      }
  
                      assert inputStream != null;
                      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                      StringBuilder sb = new StringBuilder();
  
                      String line = null;
                      while ((line = reader.readLine()) != null)
                      {
                          sb.append(line).append("\n");
                      }
                      result = sb.toString();
                  } catch (Exception e) {
                      Log.i("tagconvertstr", "["+result+"]");
                      System.out.println(e);
                  }
                  finally {
                      try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
                  }
                  return result;
              }
  
              @Override
              protected void onPostExecute(String result){
  
                  myJSON = result;
                  prepareListData();
  
              }
          }
          GetDataJSON g = new GetDataJSON();
          g.execute();
      }
  
  
  
      public String getPostDataString(JSONObject params) throws Exception {
  
          StringBuilder result = new StringBuilder();
          boolean first = true;
  
          Iterator&lt;String&gt; itr = params.keys();
  
          while(itr.hasNext()){
  
              String key= itr.next();
              Object value = params.get(key);
  
              if (first)
                  first = false;
              else
                  result.append("&amp;");
  
              result.append(URLEncoder.encode(key, "UTF-8"));
              result.append("=");
              result.append(URLEncoder.encode(value.toString(), "UTF-8"));
  
          }
          return result.toString();
      }
  
  
      private void prepareListData() {
          listDataHeader = new ArrayList&lt;String&gt;();
          listDataChild = new HashMap&lt;String, List&lt;String&gt;&gt;();
          List&lt;String&gt; top250 = new ArrayList&lt;String&gt;();
  
          try {
              peoples = new JSONArray(myJSON);
              for(int i=0;i&lt;peoples.length();i++){
                  JSONObject c = peoples.getJSONObject(i);
  
                  company_name = c.getString("firm_name");
                  from_date = c.getString("joining_date");
                  to_date = c.getString("to_date");
                  location=c.getString("duty_location");
  
                  listDataHeader.add(company_name);
                //  System.out.println(company_name+" - "+from_date+" - "+to_date+" - "+location);
                  top250.add("From Date: "+from_date);
                  top250.add("To Date: "+to_date);
                  top250.add("Location: "+location);
                  listDataChild.put(listDataHeader.get(i), top250);
  
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
  
  
  
          // Adding child data
          //listDataHeader.add("Top 250");
          //listDataHeader.add("Now Showing");
        //  listDataHeader.add("Coming Soon..");
  
          // Adding child data
  /*        top250.add("The Shawshank Redemption");
          top250.add("The Godfather");
          top250.add("The Godfather: Part II");
          top250.add("Pulp Fiction");
          top250.add("The Good, the Bad and the Ugly");
          top250.add("The Dark Knight");
          top250.add("12 Angry Men");
  
          List&lt;String&gt; nowShowing = new ArrayList&lt;String&gt;();
          nowShowing.add("The Conjuring");
          nowShowing.add("Despicable Me 2");
          nowShowing.add("Turbo");
          nowShowing.add("Grown Ups 2");
          nowShowing.add("Red 2");
          nowShowing.add("The Wolverine");
  
          List&lt;String&gt; comingSoon = new ArrayList&lt;String&gt;();
          comingSoon.add("2 Guns");
          comingSoon.add("The Smurfs 2");
          comingSoon.add("The Spectacular Now");
          comingSoon.add("The Canyons");
          comingSoon.add("Europa Report");*/
  
  
  
  
          listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
  
          // setting list adapter
          expListView.setAdapter(listAdapter);
  
  
      }
  }  
  </code></pre>
  
  <p>and ExpandableList Adapter</p>
  
  <pre><code>public class ExpandableListAdapter extends BaseExpandableListAdapter {
  
      private Context _context;
      private List&lt;String&gt; _listDataHeader; // header titles
      // child data in format of header title, child title
      private HashMap&lt;String, List&lt;String&gt;&gt; _listDataChild;
  
      public ExpandableListAdapter(Context context, List&lt;String&gt; listDataHeader,
                                   HashMap&lt;String, List&lt;String&gt;&gt; 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;
      }
  }
  </code></pre>
  
  <p>Image <a href="https://i.stack.imgur.com/3qSRp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3qSRp.png" alt="enter image description here"></a></p>