problem showing object in SimpleExpandableActivity android
<p>Hello i have a simple expandable list activity that was working fine until i changed this: <code>List&lt;Map&lt;String, String&gt;&gt; groupData = new ArrayList&lt;Map&lt;String, String&gt;&gt;();</code> for this: <code>List&lt;Map&lt;String, Image&gt;&gt; groupData = new ArrayList&lt;Map&lt;String, Image&gt;&gt;();</code> i guess that when you set the TextView items in the Simple expandable list adapter's constructor the textview is expecting to get Strings instead of objects. Is there some way to work this arround ? Or do i have to get stuck with strings? Here's some code:</p>

<pre><code> public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.expandable_list_layout);

        List&lt;User&gt; header = new ArrayList&lt;User&gt;();
        header.add(new User("John"));
        header.add(new User("Smith"));
        header.add(new User("Anderson"));
        header.add(new User("Trinity"));
        header.add(new User("Morfeo"));

        List&lt;String&gt; gretting = new ArrayList&lt;String&gt;();
        gretting.add("Hello");

        List&lt;Map&lt;String, User&gt;&gt; groupData = new ArrayList&lt;Map&lt;String, User&gt;&gt;();
        final List&lt;List&lt;Map&lt;String, String&gt;&gt;&gt; childData = new ArrayList&lt;List&lt;Map&lt;String, String&gt;&gt;&gt;();

        for (User user : header) {
            Map&lt;String, User&gt; curGroupMap = new HashMap&lt;String, User&gt;();
            groupData.add(curGroupMap);
            curGroupMap.put(NAME, user);

            List&lt;Map&lt;String, String&gt;&gt; children = new ArrayList&lt;Map&lt;String, String&gt;&gt;();
            for (String word : gretting) {
                Map&lt;String, String&gt; curChildMap = new HashMap&lt;String, String&gt;();
                children.add(curChildMap);

                curChildMap.put(NAME, word);
            }
            childData.add(children);
        }

        //our adapter

        mAdapter = new SimpleExpandableListAdapter(
                getApplicationContext(),
                groupData,
                R.layout.simple_expandable_list_item_1,
                new String[] { NAME },
                new int[] { R.id.header_text1 },
                childData,
                R.layout.simple_expandable_list_item_2,
                new String[] { NAME },
                new int[] { R.id.text1 }
                );

        ExpandableListView lv = (ExpandableListView)findViewById(R.id.list);
        lv.setAdapter(mAdapter);
    }
}
</code></pre>

<p>So the final question is: do i have to implement my own simple expandable list adapter to be able to set the text by myself?</p>

<p><strong>EDIT:</strong> Here is the trace of the error: </p>

<pre><code>02-21 08:56:54.128: ERROR/AndroidRuntime(277): java.lang.ClassCastException: se.madcoderz.categoryObject.User
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.SimpleExpandableListAdapter.bindView(SimpleExpandableListAdapter.java:249)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.SimpleExpandableListAdapter.getChildView(SimpleExpandableListAdapter.java:229)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:450)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.AbsListView.obtainView(AbsListView.java:1315)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.ListView.makeAndAddView(ListView.java:1727)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.ListView.fillDown(ListView.java:652)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.ListView.fillSpecific(ListView.java:1284)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.ListView.layoutChildren(ListView.java:1558)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.AbsListView.onLayout(AbsListView.java:1147)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.View.layout(View.java:7035)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.View.layout(View.java:7035)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.View.layout(View.java:7035)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.View.layout(View.java:7035)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.View.layout(View.java:7035)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.os.Looper.loop(Looper.java:123)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at java.lang.reflect.Method.invokeNative(Native Method)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at java.lang.reflect.Method.invoke(Method.java:521)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-21 08:56:54.128: ERROR/AndroidRuntime(277):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p><strong>2nd EDIT</strong> It's almost working but the listItems are not visible even if they're there:</p>

<pre><code>public class CategoriesAdapter2 extends SimpleExpandableListAdapter {

    private List&lt;? extends List&lt;? extends Map&lt;String, User&gt;&gt;&gt; mChildData;
    private String[] mChildFrom;
    private int[] mChildTo;

    public CategoriesAdapter2(Context context, List&lt;? extends Map&lt;String, ?&gt;&gt; groupData, int groupLayout,
                              String[] groupFrom, int[] groupTo, List&lt;List&lt;Map&lt;String, User&gt;&gt;&gt; childData,
                              int childLayout, String[] childFrom, int[] childTo) {
        super(context, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);

        mChildData = childData;
        mChildFrom = childFrom;
        mChildTo = childTo;

    }
    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        View v;
        if (convertView == null) {
            v = newChildView(isLastChild, parent);
        } else {
            v = convertView;
        }
        bindView(v, mChildData.get(groupPosition).get(childPosition), mChildFrom, mChildTo, groupPosition, childPosition);
        return v;
    }

    private void bindView(View view, Map&lt;String, User&gt; data, String[] from, int[] to, int groupPosition, int childPosition) {
        int len = to.length - 1;

        for (int i = 0; i &lt; len; i++) {
            TextView v = (TextView) 
            view.findViewById(to[i]);
            if (v != null) {
                v.setText(data.get(from[i]).getName());
            }
        }
    }
}
</code></pre>
