title: onClick child item in ExpandableListView
body: <p>I need to <strong>add onClick</strong> to the child items in <strong>ExpandableListView</strong>. I have reviewed other posts regarding this, but I could not integrate the code into mine, possibly due to a different variation of ExpandableListView codes. </p>
  
  <p>It would be great if you can provide some in code explanation as well. Many thanks.</p>
  
  <p><strong><em>Here are my source codes:</em></strong></p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>`&lt;?xml version="1.0" encoding="utf-8"?&gt;
  RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"&gt;
  
  &lt;ExpandableListView
      android:id="@+id/expLV"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;&lt;/ExpandableListView&gt;
  
  
   &lt;/RelativeLayout&gt;`
  </code></pre>
  
  <p><strong>list_parent.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"&gt;
  
  &lt;TextView
      android:id="@+id/listP"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="? 
  android:attr/expandableListPreferredItemPaddingLeft"
      android:textSize="20dp"
      android:paddingTop="20dp"
      android:paddingBottom="20dp"
      /&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>list_child.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"&gt;
  
  &lt;TextView
      android:id="@+id/listC"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="? 
  android:attr/expandableListPreferredChildPaddingLeft"
      android:textSize="14dp"
      android:paddingBottom="20dp"
      android:paddingTop="20dp"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>ExpandableListAdapter.java</strong></p>
  
  <pre><code>package com.example.ehsan.myexplistview;
  
  import android.content.Context;
  import android.graphics.Typeface;
  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 ExpandableListAdapter extends BaseExpandableListAdapter {
  
  private Context context;
  private List&lt;String&gt; listDataHeader;
  private HashMap&lt;String, List&lt;String&gt;&gt; listHashMap;
  
  public ExpandableListAdapter(Context context, List&lt;String&gt; listDataHeader, HashMap&lt;String, List&lt;String&gt;&gt; listHashMap) {
      this.context = context;
      this.listDataHeader = listDataHeader;
      this.listHashMap = listHashMap;
  }
  
  @Override
  public int getGroupCount() {
      return listDataHeader.size();
  }
  
  @Override
  public int getChildrenCount(int i) {
      return listHashMap.get(listDataHeader.get(i)).size();
  }
  
  @Override
  public Object getGroup(int i) {
      return listDataHeader.get(i);
  }
  
  @Override
  public Object getChild(int i, int i1) {
      return listHashMap.get(listDataHeader.get(i)).get(i1);
  }
  
  @Override
  public long getGroupId(int i) {
      return i;
  }
  
  @Override
  public long getChildId(int i, int i1) {
      return i1;
  }
  
  @Override
  public boolean hasStableIds() {
      return false;
  }
  
  @Override
  public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
      String parentText = (String)getGroup(i);
      if (view == null)
      {
          LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
          view=inflater.inflate(R.layout.list_parent, null);
      }
      TextView listP = (TextView)view.findViewById(R.id.listP);
      listP.setTypeface(null, Typeface.BOLD);
      listP.setText(parentText);
      return view;
  }
  
  @Override
  public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
    final String childText = (String)getChild(i,i1);
    if (view == null)
    {
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        view=inflater.inflate(R.layout.list_child, null);
    }
      TextView listC = (TextView)view.findViewById(R.id.listC);
      listC.setText(childText);
  
       view.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(i1==0){
                  Intent intent = new Intent(activity,OneTwoThree.class);
                  activity.startActivity(intent);
              }
              else if (i1 ==1){
                  Intent intent = new Intent(activity,FourFiveSix.class);
                  activity.startActivity(intent);
              }
              else if (i1 ==2){
                  Intent intent = new Intent(activity,SevenEightNine.class);
                  activity.startActivity(intent);}
              else if (i1 ==3){
                  Intent intent = new Intent(activity,TenElevenTwelve.class);
                  activity.startActivity(intent);}
          }
      });
      return view;
  }
  
  @Override
  public boolean isChildSelectable(int groupPosition, int childPosition) {
      return true;
  }
  }
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.example.ehsan.myexplistview;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.ExpandableListView;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  
  private ExpandableListView expandableListView;
  private ExpandableListAdapter expandableListAdapter;
  private List&lt;String&gt; listP;
  private HashMap&lt;String, List&lt;String&gt;&gt; listC;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      expandableListView = (ExpandableListView)findViewById(R.id.expLV);
      initData();
      expandableListAdapter = new ExpandableListAdapter(this, listP, listC);
      expandableListView.setAdapter(expandableListAdapter);
  }
  
  private void initData(){
  listP = new ArrayList&lt;&gt;();
  listC = new HashMap&lt;&gt;();
  
      listP.add("ABC");
      listP.add("DEF");
      listP.add("GHI");
      listP.add("JKL");
  
  List &lt;String&gt; abc = new ArrayList&lt;&gt;();
  abc.add("123");
  
  List &lt;String&gt; def = new ArrayList&lt;&gt;();
  def.add("456");
  def.add("789");
  
  List &lt;String&gt; ghi = new ArrayList&lt;&gt;();
  ghi.add("101112");
  ghi.add("131415");
  ghi.add("161718");
  
  List &lt;String&gt; jkl = new ArrayList&lt;&gt;();
  jkl.add("192021");
  jkl.add("222324");
  jkl.add("252627");
  jkl.add("282930");
  
  listC.put(listP.get(0),abc);
  listC.put(listP.get(1),def);
  listC.put(listP.get(2),ghi);
  listC.put(listP.get(3),jkl);
  }
  }
  </code></pre>