title: Implementing an expandable listview in tab fragment
body: <p>Followed the tutorial from androidhive to create an expandable listview.</p>
  
  <p><a href="http://www.learn-android-easily.com/2013/07/android-tabwidget-example.html" rel="nofollow">http://www.learn-android-easily.com/2013/07/android-tabwidget-example.html</a>
  Followed tutorial to create horizontal tabs. </p>
  
  <p>Edited the Tab Widget Example (Second tutorial) to put the expandable listview in the tabs. Did this by creating the expandable list adapter java file in the project and copying the expandable list code into the tab activity file. (Brought in the required xml files too) The tab activity then looked like this:</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.widget.ExpandableListView;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  public class Tab1Activity 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.expandable_listview);
  
          // 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);
      }
  
      // 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("Top 250");
          listDataHeader.add("Now Showing");
          listDataHeader.add("Coming Soon..");
  
  
          // Adding child data
          List&lt;String&gt; top250 = new ArrayList&lt;String&gt;();
          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");
  
          listDataChild.put(listDataHeader.get(0), top250); 
          // Header, Child data
          listDataChild.put(listDataHeader.get(1), nowShowing);
          listDataChild.put(listDataHeader.get(2), comingSoon);
      }
  }
  </code></pre>
  
  <p>Worked fine. Tried to do the same with project from here:
  <a href="http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/" rel="nofollow">http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/</a>
  Here I've got a few errors. I think that setContentView can't be used with fragments so I got rid of it and kept the original inflater.
  Similarly I think I need to use something else instead of the findViewById and change my arguments for the ExpandableListAdapter(). Not really sure what this needs to be changes to however..</p>
  
  <p>My tab fragment:</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ExpandableListView;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  public class GamesFragment extends Fragment 
  {
  
      ExpandableListAdapter listAdapter;
      ExpandableListView expListView;
      List&lt;String&gt; listDataHeader;
      HashMap&lt;String, List&lt;String&gt;&gt; listDataChild;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
      {
  
          View rootView = inflater.inflate(R.layout.fragment_games, container, false);
  
  
          super.onCreate(savedInstanceState);
  
          // 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);
  
          return rootView;
      }
  
      // 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("Top 250");
          listDataHeader.add("Now Showing");
          listDataHeader.add("Coming Soon..");
  
          // Adding child data
          List&lt;String&gt; top250 = new ArrayList&lt;String&gt;();
          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");
  
          listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
          listDataChild.put(listDataHeader.get(1), nowShowing);
          listDataChild.put(listDataHeader.get(2), comingSoon);
      }
  }
  </code></pre>
  
  <p>My tab fragment layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="#ff8400" &gt;
  
      &lt;ExpandableListView
          android:id="@+id/lvExp"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" &gt;
      &lt;/ExpandableListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Do let me know if I am going about this the wrong way. All I'm looking to do is create swipe views with tabs which have expandable listviews in them.</p>