title: How to set different images in Expandable ListView parents?
body: <p>I made an ExpandableListView and now I want to set different images in each group. For example, in the Dress group I want to set a photo of a dress, in Shoes a photo of a shoe etc.</p>
  
  <p>Here is my layout:</p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="40dp"
      android:background="#ffffff"
      android:clickable="true"
      android:orientation="vertical"
      android:paddingLeft="40dp"
      android:paddingStart="40dp"
      tools:context=".MainActivity" &gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="39dp"
          android:gravity="center_vertical"&gt;
  
          &lt;ImageView android:id="@+id/image1"
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_marginLeft="25dp"/&gt;
  
  
  
          &lt;TextView
              android:id="@+id/textView1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:textIsSelectable="true"
              android:textColor="#f30f30"
              android:textSize="24sp"
              android:textStyle="bold" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>package com.example.user.expandablelist;
  
  import android.app.Activity;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseExpandableListAdapter;
  import android.widget.CheckedTextView;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  
  
  public class MyExpandableAdapter  extends BaseExpandableListAdapter {
  
  
      private Activity activity;
      private ArrayList&lt;Object&gt; childtems;
      private LayoutInflater inflater;
      private ArrayList&lt;String&gt; parentItems, child;
  
  
      public MyExpandableAdapter(ArrayList&lt;String&gt; parents, ArrayList&lt;Object&gt; childern) {
          this.parentItems = parents;
          this.childtems = childern;
      }
  
      public void setInflater(LayoutInflater inflater, Activity activity) {
          this.inflater = inflater;
          this.activity = activity;
      }
  
      @Override
      public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  
          child = (ArrayList&lt;String&gt;) childtems.get(groupPosition);
  
          TextView textView = null;
  
          if (convertView == null) {
              convertView = inflater.inflate(R.layout.group, null);
          }
  
          textView = (TextView) convertView.findViewById(R.id.textView1);
          textView.setText(child.get(childPosition));
  
          convertView.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View view) {
                  Toast.makeText(activity, child.get(childPosition),
                          Toast.LENGTH_SHORT).show();
              }
          });
  
          return convertView;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
  
          if (convertView == null) {
              convertView = inflater.inflate(R.layout.row, null);
          }
  
  
  
  
  
          ((CheckedTextView) convertView).setText(parentItems.get(groupPosition));
          ((CheckedTextView) convertView).setChecked(isExpanded);
  
          return convertView;
      }
  
      @Override
      public Object getChild(int groupPosition, int childPosition) {
          return null;
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          return 0;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
          return ((ArrayList&lt;String&gt;) childtems.get(groupPosition)).size();
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          return null;
      }
  
      @Override
      public int getGroupCount() {
          return parentItems.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 boolean hasStableIds() {
          return false;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          return false;
      }
  
  }
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>package com.example.user.expandablelist;
  
  
  import android.app.ExpandableListActivity;
  import android.content.Context;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.widget.ExpandableListView;
  
  import java.util.ArrayList;
  
  
  public class MainActivity extends ExpandableListActivity {
  
      private ArrayList&lt;String&gt; parentItems = new ArrayList&lt;&gt;();
      private ArrayList&lt;Object&gt; childItems = new ArrayList&lt;&gt;();
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          ExpandableListView expandableList = getExpandableListView();
  
          expandableList.setDividerHeight(2);
          expandableList.setGroupIndicator(null);
          expandableList.setClickable(true);
  
          setGroupParents();
          setChildData();
  
          MyExpandableAdapter adapter = new MyExpandableAdapter(parentItems, childItems);
  
          adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this);
          expandableList.setAdapter(adapter);
          expandableList.setOnChildClickListener(this);
  }
  
      public void setGroupParents() {
          parentItems.add("Shorts" );
          parentItems.add("Trousers");
          parentItems.add("Skirts");
          parentItems.add("Dresses");
          parentItems.add("Shoes");
  
      }
  
  
      public void setChildData() {
  
          // Shirts
          ArrayList&lt;String&gt; child = new ArrayList&lt;&gt;();
          child.add("Basic T-Shirts" );
          child.add("Printed T-shirts");
          child.add("Tops");
          child.add("Long-Sleeved Shirts");
          childItems.add(child);
  
          // Trousers
          child = new ArrayList&lt;&gt;();
          child.add("Jeans");
          child.add("Casual");
          child.add("Business");
          child.add("Shorts");
          child.add("Leggings");
          childItems.add(child);
  
          // Skirts
          child = new ArrayList&lt;&gt;();
          child.add("Mini");
          child.add("Maxi");
          child.add("Midi");
          childItems.add(child);
  
          // Dresses
          child = new ArrayList&lt;&gt;();
          child.add("Mini");
          child.add("Maxi");
          child.add("Midi");
          child.add("Weddings &amp; Parties");
          childItems.add(child);
  
          // Shoes
          child = new ArrayList&lt;&gt;();
          child.add("Sneakers");
          child.add("High-Heels");
          child.add("Wedges");
          child.add("Sandals");
          childItems.add(child);
  
  
      }
  
  }
  </code></pre>