Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3997914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:27:37+00:00 2026-05-20T07:27:37+00:00

Hello i have a simple expandable list activity that was working fine until i

  • 0

Hello i have a simple expandable list activity that was working fine until i changed this: List<Map<String, String>> groupData = new ArrayList<Map<String, String>>(); for this: List<Map<String, Image>> groupData = new ArrayList<Map<String, Image>>(); 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:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.expandable_list_layout);

        List<User> header = new ArrayList<User>();
        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<String> gretting = new ArrayList<String>();
        gretting.add("Hello");

        List<Map<String, User>> groupData = new ArrayList<Map<String, User>>();
        final List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();

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

            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            for (String word : gretting) {
                Map<String, String> curChildMap = new HashMap<String, String>();
                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);
    }
}

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?

EDIT: Here is the trace of the error:

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)

2nd EDIT It’s almost working but the listItems are not visible even if they’re there:

public class CategoriesAdapter2 extends SimpleExpandableListAdapter {

    private List<? extends List<? extends Map<String, User>>> mChildData;
    private String[] mChildFrom;
    private int[] mChildTo;

    public CategoriesAdapter2(Context context, List<? extends Map<String, ?>> groupData, int groupLayout,
                              String[] groupFrom, int[] groupTo, List<List<Map<String, User>>> 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<String, User> data, String[] from, int[] to, int groupPosition, int childPosition) {
        int len = to.length - 1;

        for (int i = 0; i < len; i++) {
            TextView v = (TextView) 
            view.findViewById(to[i]);
            if (v != null) {
                v.setText(data.get(from[i]).getName());
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:27:37+00:00Added an answer on May 20, 2026 at 7:27 am

    Now it’s working but i don’t like the solution. I made a new class and extended BaseExpandableListAdapter, the same superclass SimpleExpandableListAdapter extends. I don’t like this solution, if there’s a better solution please let me know.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WebView-based activity that follows the Hello, WebView example to enable
file = [file1,file2,...].join( ) `paste #{file}` Hello, I have this simple problem that has
I have simple java app that prints `hello world!' on console. It is packed
I have a simple Hello World application in Python that i'm using with AppEngine,
I have a simple PHP app that prints 'hello world'. When I run it
Hello I have a simple form on my site that allows users to send
Hello I have a simple wcf service like this, with a test method which
I have done this: $ z() { echo 'hello world'; } How do I
Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt
Say for example I have the following string: var testString = Hello, world; And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.