title: Inflate Custom Layout ExpandableList Fragment
body: <p>I've been trying for two days to inflate my custom Layout for both groups and children in the expandable list using Fragment without success. I always get the error :
  java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams, but i do not know what it means!!</p>
  
  <p>Here is my Fragment Class and the Adapter</p>
  
  <pre><code>public class ExpandableListFragment extends Fragment {
  /**
   * The fragment argument representing the section number for this
   * fragment.
   */
  private static final String ARG_SECTION_NUMBER = "section_number";
  
  /**
   * Returns a new instance of this fragment for the given section number.
   */
  public static ExpandableListFragment newInstance(int sectionNumber) {
      ExpandableListFragment fragment = new ExpandableListFragment();
      Bundle args = new Bundle();
      args.putInt(ARG_SECTION_NUMBER, sectionNumber);
      fragment.setArguments(args);
      return fragment;
  }
  
  public ExpandableListFragment() {
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_catalogo,
              container, false);
       ExpandableListView elv = (ExpandableListView) rootView.findViewById(R.id.lista_catalogo);
       MiaExpandableListAdapter mela = new MiaExpandableListAdapter(getActivity());
          mela.loadJSONFromAsset();
          elv.setAdapter(mela);           
      return rootView;
  }
  
  
  public class MiaExpandableListAdapter extends BaseExpandableListAdapter {
  
      private String[] groups ={"sedie", "tavoli" , "divani" , "letti" , "lampade"};
  
      private String[][] children;
  
      private Context ctx;
      private LayoutInflater inflater;
  
      public MiaExpandableListAdapter(Context ct)
      {
          ctx =ct;
          inflater = (LayoutInflater) ctx
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
  
      public String loadJSONFromAsset() {
          String json = null;
          try {
  
              InputStream is = ExpandableListFragment.this.getActivity().getAssets().open("prova.json");
  
              int size = is.available();
  
              byte[] buffer = new byte[size];
  
              is.read(buffer);
  
              is.close();
  
              json = new String(buffer, "UTF-8");
              //Log.d("JSON", json);
  
  
  
          } catch (IOException ex) {
              ex.printStackTrace();
              return null;
          }
  
          children = new String[5][2];
          try{
              JSONObject jsonResponse = new JSONObject(json);
              JSONArray nome_oggetto = jsonResponse.getJSONArray("sedie");
              for (int i=0; i&lt;nome_oggetto.length(); i++) {
                  JSONObject prodotto = nome_oggetto.getJSONObject(i);
                  children[0][i] = prodotto.getString("name");
                  //Log.d("JSONSEDIE", children[0][i]);
  
              }
              }catch(JSONException ex){ex.printStackTrace();}
  
          try{
              JSONObject jsonResponse = new JSONObject(json);
              JSONArray nome_oggetto = jsonResponse.getJSONArray("tavoli");
              for (int i=0; i&lt;nome_oggetto.length(); i++) {
                  JSONObject prodotto = nome_oggetto.getJSONObject(i);
                  children[1][i] = prodotto.getString("name");
  
              }
              }catch(JSONException ex){ex.printStackTrace();}
          try{
              JSONObject jsonResponse = new JSONObject(json);
              JSONArray nome_oggetto = jsonResponse.getJSONArray("divani");
              for (int i=0; i&lt;nome_oggetto.length(); i++) {
                  JSONObject prodotto = nome_oggetto.getJSONObject(i);
                  children[2][i] = prodotto.getString("name");
  
              }
              }catch(JSONException ex){ex.printStackTrace();}
          try{
              JSONObject jsonResponse = new JSONObject(json);
              JSONArray nome_oggetto = jsonResponse.getJSONArray("letti");
              for (int i=0; i&lt;nome_oggetto.length(); i++) {
                  JSONObject prodotto = nome_oggetto.getJSONObject(i);
                  children[3][i] = prodotto.getString("name");
  
              }
              }catch(JSONException ex){ex.printStackTrace();}
          try{
              JSONObject jsonResponse = new JSONObject(json);
              JSONArray nome_oggetto = jsonResponse.getJSONArray("lampade");
              for (int i=0; i&lt;nome_oggetto.length(); i++) {
                  JSONObject prodotto = nome_oggetto.getJSONObject(i);
                  children[4][i] = prodotto.getString("name");
  
              }
              }catch(JSONException ex){ex.printStackTrace();}
  
  
  
          return json;
  
      }
  
      @Override
      public int getGroupCount() {
          // TODO Auto-generated method stub
          return groups.length;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
          // TODO Auto-generated method stub
          return children[groupPosition].length;
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          // TODO Auto-generated method stub
          return groups[groupPosition];
      }
  
      @Override
      public Object getChild(int groupPosition, int childPosition) {
          // TODO Auto-generated method stub
          return children[groupPosition][childPosition];
      }
  
      @Override
      public long getGroupId(int groupPosition) {
          // TODO Auto-generated method stub
          return groupPosition;
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          // TODO Auto-generated method stub
          return childPosition;
      }
  
      @Override
      public boolean hasStableIds() {
          // TODO Auto-generated method stub
          return true;
      }       @Override
      public View getGroupView(int groupPosition, boolean isExpanded,
              View convertView, ViewGroup parent) {
          convertView = inflater.inflate(R.layout.group_item, null);
          TextView tv = (TextView) convertView.findViewById(R.id.group_catalogo);
          tv.setText(getGroup(groupPosition).toString());
          return tv;
  
      }
  
      @Override
      public View getChildView(int groupPosition, int childPosition,
              boolean isLastChild, View convertView, ViewGroup parent) {
  
          convertView = inflater.inflate(R.layout.child_item, null);
          TextView tv = (TextView) convertView.findViewById(R.id.child_catalogo);
          tv.setText(getChild(groupPosition, childPosition).toString());
  
          return tv;
      }
     @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          // TODO Auto-generated method stub
          return true;
      }
  }
  }
  </code></pre>
  
  <p>Here are the layouts i tried to inflate: child_item.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &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="45dp"
  android:orientation="vertical" &gt;
  &lt;TextView
      android:id="@+id/child_catalogo"
      android:layout_width="fill_parent"
      android:layout_height="45dp"
      android:layout_marginRight="15dp"
      android:textColor="#FF0000"
      android:textSize="17dp" /&gt;  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and group_item.xml:</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="45dp"
  android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/group_catalogo"
      android:layout_width="fill_parent"
      android:layout_height="45dp"
      android:layout_marginRight="15dp"
      android:textColor="#FF0000"
      android:textSize="30dp" /&gt;  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Finally the Fragment layout fragment_catalogo.xml:</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="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.lab2mad.ExpandableListFragment" &gt;
  
  &lt;ExpandableListView
      android:id="@+id/lista_catalogo"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  &lt;/ExpandableListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>if someone could give me some hints i would be very gratefully.
  Thank you</p>
  
  <p>Here you go the error Log:</p>
  
  <blockquote>
    <p>05-05 21:51:15.718: W/dalvikvm(11944): threadid=1: thread exiting with uncaught exception (group=0x40018578)
    05-05 21:51:15.835: E/AndroidRuntime(11944): FATAL EXCEPTION: main
    05-05 21:51:15.835: E/AndroidRuntime(11944): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.ListView.setupChild(ListView.java:1816)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.ListView.makeAndAddView(ListView.java:1785)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.ListView.fillDown(ListView.java:705)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.ListView.fillFromTop(ListView.java:762)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.ListView.layoutChildren(ListView.java:1633)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.AbsListView.onLayout(AbsListView.java:1422)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.View.layout(View.java:7175)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.os.Handler.dispatchMessage(Handler.java:99)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.os.Looper.loop(Looper.java:130)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at java.lang.reflect.Method.invokeNative(Native Method)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at java.lang.reflect.Method.invoke(Method.java:507)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    05-05 21:51:15.835: E/AndroidRuntime(11944):    at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>
  
  <p>Thanks Again</p>