title: how to apply a single background for group and child in expandablelistview
body: <p>how to apply a single background for both group and child in expandable listview?</p>
  <p>expected output</p>
  <h2><img src="https://i.stack.imgur.com/fcOtE.png" alt="enter image description here" /></h2>
  <p>Edit:</p>
  <hr />
  <p>MainActivity.java</p>
  <pre><code>package info.androidhive.expandablelistview;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ExpandableListView;
  import android.widget.ExpandableListView.OnChildClickListener;
  import android.widget.ExpandableListView.OnGroupClickListener;
  import android.widget.ExpandableListView.OnGroupCollapseListener;
  import android.widget.ExpandableListView.OnGroupExpandListener;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      ExpandableListAdapter listAdapter;
      ExpandableListView expListView;
      List&lt;String&gt; listDataHeader;
      HashMap&lt;String, List&lt;String&gt;&gt; listDataChild;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // get the listview
          expListView = (ExpandableListView) findViewById(R.id.lvExp);
  
          // preparing list data
          prepareListData();
  
          listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
  
          // setting list adapter
          expListView.setAdapter(listAdapter);
  
          // Listview Group click listener
          expListView.setOnGroupClickListener(new OnGroupClickListener() {
  
              @Override
              public boolean onGroupClick(ExpandableListView parent, View v,
                      int groupPosition, long id) {
                  // Toast.makeText(getApplicationContext(),
                  // &quot;Group Clicked &quot; + listDataHeader.get(groupPosition),
                  // Toast.LENGTH_SHORT).show();
                  return false;
              }
          });
  
          // Listview Group expanded listener
          expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
  
              @Override
              public void onGroupExpand(int groupPosition) {
                  Toast.makeText(getApplicationContext(),
                          listDataHeader.get(groupPosition) + &quot; Expanded&quot;,
                          Toast.LENGTH_SHORT).show();
              }
          });
          expListView.setDivider(null);
          expListView.setChildDivider(null);
          // Listview Group collasped listener
          expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
  
              @Override
              public void onGroupCollapse(int groupPosition) {
                  Toast.makeText(getApplicationContext(),
                          listDataHeader.get(groupPosition) + &quot; Collapsed&quot;,
                          Toast.LENGTH_SHORT).show();
  
              }
          });
  
          // Listview on child click listener
          expListView.setOnChildClickListener(new OnChildClickListener() {
  
              @Override
              public boolean onChildClick(ExpandableListView parent, View v,
                      int groupPosition, int childPosition, long id) {
                  // TODO Auto-generated method stub
                  Toast.makeText(
                          getApplicationContext(),
                          listDataHeader.get(groupPosition)
                                  + &quot; : &quot;
                                  + listDataChild.get(
                                          listDataHeader.get(groupPosition)).get(
                                          childPosition), Toast.LENGTH_SHORT)
                          .show();
                  return false;
              }
          });
      }
  
      /*
       * Preparing the list data
       */
      private void prepareListData() {
          listDataHeader = new ArrayList&lt;String&gt;();
          listDataChild = new HashMap&lt;String, List&lt;String&gt;&gt;();
  
          // Adding child data
          listDataHeader.add(&quot;Top 250&quot;);
          listDataHeader.add(&quot;Now Showing&quot;);
          listDataHeader.add(&quot;Coming Soon..&quot;);
  
          // Adding child data
          List&lt;String&gt; top250 = new ArrayList&lt;String&gt;();
          top250.add(&quot;The Shawshank Redemption&quot;);
          top250.add(&quot;The Godfather&quot;);
          top250.add(&quot;The Godfather: Part II&quot;);
          top250.add(&quot;Pulp Fiction&quot;);
          top250.add(&quot;The Good, the Bad and the Ugly&quot;);
          top250.add(&quot;The Dark Knight&quot;);
          top250.add(&quot;12 Angry Men&quot;);
  
          List&lt;String&gt; nowShowing = new ArrayList&lt;String&gt;();
          nowShowing.add(&quot;The Conjuring&quot;);
          nowShowing.add(&quot;Despicable Me 2&quot;);
          nowShowing.add(&quot;Turbo&quot;);
          nowShowing.add(&quot;Grown Ups 2&quot;);
          nowShowing.add(&quot;Red 2&quot;);
          nowShowing.add(&quot;The Wolverine&quot;);
  
          List&lt;String&gt; comingSoon = new ArrayList&lt;String&gt;();
          comingSoon.add(&quot;2 Guns&quot;);
          comingSoon.add(&quot;The Smurfs 2&quot;);
          comingSoon.add(&quot;The Spectacular Now&quot;);
          comingSoon.add(&quot;The Canyons&quot;);
          comingSoon.add(&quot;Europa Report&quot;);
  
          listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
          listDataChild.put(listDataHeader.get(1), nowShowing);
          listDataChild.put(listDataHeader.get(2), comingSoon);
      }
  }
  </code></pre>
  <hr />
  <p>ExpandableListAdapter.java</p>
  <pre><code>package info.androidhive.expandablelistview;
  
  import java.util.HashMap;
  import java.util.List;
  
  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.ExpandableListView;
  import android.widget.TextView;
  
  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);
              convertView.setBackgroundResource(R.drawable.bubble_green);
              
              ExpandableListView mExpandableListView = (ExpandableListView) parent;
              mExpandableListView.expandGroup(groupPosition);
          }
  
          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>
  <hr />
  <p>activity_main.xml</p>
  <pre><code> &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
      &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;fill_parent&quot;
          android:orientation=&quot;vertical&quot;
           &gt;
      
                  &lt;ExpandableListView
                      android:id=&quot;@+id/lvExp&quot;
                      android:layout_height=&quot;match_parent&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:groupIndicator=&quot;@null&quot;
                      /&gt;   
      
      &lt;/LinearLayout&gt;
  </code></pre>
  <hr />
  <p>list_item.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;55dip&quot;
      android:orientation=&quot;vertical&quot; &gt;
  
      &lt;TextView
          android:id=&quot;@+id/lblListItem&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:textSize=&quot;17dip&quot;
          android:paddingTop=&quot;5dp&quot;
          android:paddingBottom=&quot;5dp&quot;
          android:textColor=&quot;#000000&quot;
          android:paddingLeft=&quot;?android:attr/expandableListPreferredChildPaddingLeft&quot; /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <hr />
  <p>list_group.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:orientation=&quot;vertical&quot;
      android:padding=&quot;8dp&quot; 
      &gt;
  
  
      &lt;TextView
          android:id=&quot;@+id/lblListHeader&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:paddingLeft=&quot;?android:attr/expandableListPreferredItemPaddingLeft&quot;
          android:textSize=&quot;17dp&quot;
           /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <hr />
  <p>AndroidManifest.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;info.androidhive.expandablelistview&quot;
      android:versionCode=&quot;1&quot;
      android:versionName=&quot;1.0&quot; &gt;
  
      &lt;uses-sdk
          android:minSdkVersion=&quot;8&quot;
          android:targetSdkVersion=&quot;17&quot; /&gt;
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@drawable/ic_launcher&quot;
          android:label=&quot;Expandable&quot;
           &gt;
          &lt;activity
              android:name=&quot;info.androidhive.expandablelistview.MainActivity&quot;
              
              &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <hr />
  <p>here is the 9 patch image</p>
  <p><img src="https://i.stack.imgur.com/hoNTV.png" alt="enter image description here" /></p>