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

  • SEARCH
  • Home
  • 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 6835297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:12:57+00:00 2026-05-26T23:12:57+00:00

I have an expandable list in android and I can fill it with string

  • 0

I have an expandable list in android and I can fill it with string easily but now I want to add a drawable on each row of the list (a different one on each row), what’s the easiest way to do this with the code I already have? Thanks.

public class Physical extends ExpandableListActivity {
public static final int GROUPS = 1;
public SimpleExpandableListAdapter expListAdapter;
private boolean expanded = true;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.phys_sub); 

    String [] cats = { "phy1", "phys2" };

    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
    for (int i = 0; i < GROUPS; i++) {
        Map<String, String> curGroupMap = new HashMap<String, String>();
        groupData.add(curGroupMap);
        curGroupMap.put( "group", "Categories" );

        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
        for( int n = 0 ; n < cats.length ; n++ ) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            curChildMap.put( "child", cats[n] );
            children.add(curChildMap);
        }
        childData.add(children);
    }

    expListAdapter =
            new SimpleExpandableListAdapter(
                    /* context */
                    this,
                    /* creates Group list */
                    groupData, 
                    /*Group item layout XML */
                    R.layout.group_row,    
                    /* the key of each group element (not child's) */
                    new String[] { "group" },
                    /* data under the key goes into this TextView */
                    new int[] { R.id.group_text }, 
                    /* creates Child List (sub-level entries) */
                    childData,
                    /* layout for children in list */
                    R.layout.child_sub,
                    /* the key of each child element */
                    new String[] { "child" },
                    /* data under the child keys go into this textView */
                    new int[] { R.id.child_text }
                );
            /* sets up and initializes the adapter for the list */
            setListAdapter(expListAdapter);

            getExpandableListView().setOnGroupExpandListener( new OnGroupExpandListener() {
                 public void onGroupExpand(int groupPosition) {
                     expanded = true;
                   }
               });
            getExpandableListView().setOnGroupCollapseListener( new OnGroupCollapseListener() {
                public void onGroupCollapse(int groupPosition) {
                    expanded = false;
                }
            });
            if (expanded != false ) {
                getExpandableListView().expandGroup(0);
            }
}
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, final int childPosition, long id) {
    switch (childPosition) {
    case 0:
        Intent spine_plus_intent = new Intent(Physical.this, SpinePlus.class);
        startActivity(spine_plus_intent);
        finish();
        break;
    }
    return true;
}

}

  • 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-26T23:12:57+00:00Added an answer on May 26, 2026 at 11:12 pm

    you’d define a custom expandable list adapter and redefine the getchildview / getgroupview.

    From there you have 2 routes to follow: one, you can programmatically add the imageviews into the child/group view (i’d discourage you from this approach), or you define an xml layout file for the child/group view and inflate it (and possibly edit the content dynamically)

    Simple adapters aren’t flexible enough to achieve good results. Expecially when you want custom views for their elements. (Not to mention scalability: always project and code keeping in mind that your requirements may enlarge in the future and a flexible base allows more freedom and prevents you from scratching too much code)

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

Sidebar

Related Questions

I want to add an image icon in expandable list view .I have seen
I'm trying to make a list item expandable. Basically, I want to have a
I m working on android. i have made expandable list view and its working
I have this code for an expandable list, I want to have a checkbox
I have a set of divs that I want to make collapsible/expandable using jQuery's
I have an AlertDialog populated by an ExpandableListView. The list itself works perfectly, but
Hello i have a simple expandable list activity that was working fine until i
I have an expandable list that contains groups : continents and child : countries.
I have a sqlite database in my application. I want to make an expandable
I current have an expandable list that I'd like to be able to search

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.