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 5954555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:59:15+00:00 2026-05-22T17:59:15+00:00

I have the following source code, this is an Expandable list it has a

  • 0

I have the following source code, this is an Expandable list it has a child list, which has some view like Image button, Image button, i want to do event handling on these views. please
provide me source code for the following.

public class ExpList extends ExpandableListActivity {
ImageView imageView, heart;
View view;
ArrayList count = new ArrayList();
//private Context context;
ExpandableListAdapterDemo madapter;
static final String shades[][] = {
// Shades of grey
{ “Episode1”, “Episode1”, “Episode1”, “Episode1”, “Episode1” },
// Shades of blue
{ “Episode2”, “Episode2”, “Episode2”, “Episode2”, “Episode2”,
“Episode2” },
{ “Episode3”, “Episode3”, “Episode3” },
// Shades of red
{ “Episode4”, “Episode4”, “Episode4”, “Episode4” },
{ “Episode5”, “Episode5”, “Episode5”, “Episode5” },
{ “Episode6”, “Episode6”, “Episode6”, “Episode6”, “Episode6”,
“Episode6” },
{ “Episode7”, “Episode7”, “Episode7”, “Episode7”, “Episode7”,
“Episode7” },
{ “Episode8”, “Episode8”, “Episode8”, “Episode8”, “Episode8” },
{ “Episode9”, “Episode9”, “Episode9”, “Episode9”, “Episode9”,
“Episode9”, “Episode9” },
{ “Episode10”, “Episode10”, “Episode10”, “Episode10”, “Episode10”,
“Episode10”, “Episode10”, “Episode10” }

};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);
    Log.i("ARRy lentgh_____________", " " + shades.length);
    for (int n = 0; n < shades.length; n++) {

        count.add(Integer.toString(shades[n].length));
        Log.i("item y lentgh_____________", " " + shades[n].length);
    }
    for (int n = 0; n < count.size(); n++) {
        Log.i("List Elements are_____________", " " + count.get(n));
        // count.add(Integer.toString(shades[n].length));
    }
    madapter= new ExpandableListAdapterDemo(this,createGroupList(),createChildList());
    SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
            this, createGroupList(), // groupData describes the first-level
                                        // entries
            R.layout.parent_row, // Layout for the first-level entries
            new String[] { "count" }, // Key in the groupData maps to
                                        // display
            new int[] { R.id.episode_count }, // Data under "colorName" key
                                                // goes into this TextView
            createChildList(), // childData describes second-level entries
            R.layout.child_row, // Layout for second-level entries
            new String[] { "shadeName" }, // Keys in childData maps to
                                            // display
            new int[] { R.id.childname } // Data under the keys above go
                                            // into these TextViews
    );

    setListAdapter(expListAdapter);

    final ExpandableListView exlv = this.getExpandableListView();
    Log.i("exlv.getWidth():widthhhhhhhhh", "" + exlv.getWidth() + 50);
    exlv.setIndicatorBounds(exlv.getWidth() + 30, exlv.getWidth() + 520);


    exlv.setOnGroupExpandListener(new OnGroupExpandListener() {

        @Override
        public void onGroupExpand(int arg0) {
            // TODO Auto-generated method stub
            Log.i("Group Expand id is ", " " + exlv.getChildAt(arg0)+"Count is "+exlv.getChildCount()
                    + "   ");
            LinearLayout linearLayout= (LinearLayout) exlv.getChildAt(arg0);
            //LinearLayout linearLayout= (LinearLayout)findViewById(R.layout.child_row);
            Log.i("Linear layout is ", " " + linearLayout
                    + "   ");
            imageView= (ImageView)linearLayout.findViewById(R.id.imageView2);

            Log.i("Image view id is ", " " + imageView
                    + "   ");

        }
    });
    exlv.setOnGroupClickListener(new OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView arg0, View arg1,
                int arg2, long arg3) {

            LinearLayout linearLayout= (LinearLayout) arg0.getChildAt(arg2);

            imageView= (ImageView)linearLayout.findViewById(R.id.imageView2);
            Log.i("Image view id is ", " " + imageView
                    + "   ");
            Log.i("View is", ";;;;;;;;;;;; " + arg1.findViewById(R.id.imageView2)
                    + " layout  "+linearLayout+"image id on group "+imageView);
            Toast.makeText(getBaseContext(), "Group clicked ",
                    Toast.LENGTH_SHORT).show();

            return false;
        }
    });

    exlv.setOnChildClickListener(new OnChildClickListener() {

        public boolean onChildClick(ExpandableListView arg0, View arg1,
                int arg2, int arg3, long arg4) {


            Toast.makeText(ExpList.this,
                    "Child ItemClicked " + arg2 + " " + arg3,
                    Toast.LENGTH_SHORT).show();

            imageView = (ImageView)arg1.findViewById(R.id.imageView2);
            Log.i("ImageView Value "," hi "+imageView.toString());
              imageView.setOnClickListener(new OnClickListener() {

              @Override public void onClick(View arg0) { // TODO Auto-generated
                  Intent intent = new Intent(ExpList.this,DemoActivity.class);
                     startActivity(intent); 
            } });


            // TODO Auto-generated method stub
            return false;
        }
    });

    /*
     * imageView.setOnClickListener(new OnClickListener() {
     * 
     * @Override public void onClick(View arg0) { // TODO Auto-generated
     * method stub Intent intent = new
     * Intent(ExpList.this,DemoActivity.class); startActivity(intent); } });
     */

    for (int n = 0; n < count.size(); n++) {
        Log.i("Values of episode is ", " " + count.get(n));
    }

}
/**
 * Creates the group list out of the colors[] array according to the
 * structure required by SimpleExpandableListAdapter. The resulting List
 * contains Maps. Each Map contains one entry with key "colorName" and value
 * of an entry in the colors[] array.
 */

private List createGroupList() {
    ArrayList result = new ArrayList();

    Log.i("size of count is", " " + count.size());
    for (int i = 0; i < shades.length; i++) {
        HashMap m = new HashMap();
        m.put("count", count.get(i));
        result.add(m);
    }
    return result;
}
/**
 * Creates the child list out of the shades[] array according to the
 * structure required by SimpleExpandableListAdapter. The resulting List
 * contains one list for each group. Each such second-level group contains
 * Maps. Each such Map contains two keys: "shadeName" is the name of the
 * shade and "rgb" is the RGB value for the shade.
 */
private List createChildList() {
    ArrayList result = new ArrayList();
    Log.i("two dim Array Size is ", " Size is " + shades.length);
    for (int i = 0; i < shades.length; ++i) {
        // Second-level lists
        ArrayList secList = new ArrayList();
        for (int j = 0; j < shades[i].length; j++) {

            HashMap child = new HashMap();
            child.put("shadeName", shades[i][j]);
            secList.add(child);
        }
        result.add(secList);
    }
    return result;
}

public class ExpandableListAdapterDemo extends BaseExpandableListAdapter {

    @Override
    public boolean areAllItemsEnabled() {
        return true;
    }
    private Context context;
    private ArrayList<String> groups;
    private ArrayList<ArrayList> children;
      public ExpandableListAdapterDemo(Context context, List groups, List chiildren)
      {
          this.context = context; 
          this.groups = (ArrayList<String>) groups;
          this.children = (ArrayList<ArrayList>) chiildren; 
      }
        /**
     * A general add method, that allows you to add a Vehicle to this list
     * 
     * Depending on if the category opf the vehicle is present or not, the
     * corresponding item will either be added to an existing group if it
     * exists, else the group will be created and then the item will be
     * added
     * 
     * @param vehicle
     */

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return children.get(groupPosition).get(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    // Return a child view. You can load your custom layout here.
    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {


        ImageView tv = (ImageView) convertView
                .findViewById(R.id.imageView2);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Log.i("hiiiiiiiiiiiiiiiii","image clicked");
                Intent intent = new Intent(ExpList.this, DemoActivity.class);
                startActivity(intent);
            }
        });


        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return children.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    // Return a group view. You can load your custom layout here.
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        // String group = (String) getGroup(groupPosition);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int arg0, int arg1) {
        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-22T17:59:16+00:00Added an answer on May 22, 2026 at 5:59 pm

    I have a solution for you, it’s so simple.
    Let’s use two dimensions array to give your adapter data to show in the views, so when you want to access the data in one child to change something(maybe string of textview, image resource of Imageview, etc), you just need to remove the element of the two dimensions array which has the same position as in your expandablelistview, then add a new element with changed data at that position too. Then call adapter.notifyDataSetChanged();
    It’s a bit hard to understand, so see the code, it should look like:

            childs.get(1).remove(1);
        childs.get(1).add(1, new ChildData("changed textview", BitmapFactory.decodeResource(getResources(), R.drawable.no_avatar)));
        adapter.notifyDataSetChanged();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to download source code for android core apps like Settings.I have following
I have the following source code. testObj = {} function testFun() { this.name =
I have the following SVG source code that generates a number of boxes with
I have seen a web page source code containing the following css declaration at
I have the following code: <video width=640 height=360 controls id=video-player poster=/movies/poster.png> <source src=/movies/640x360.m4v type='video/mp4;
I have a data source with about 2000 lines that look like the following:
gcc 4.4.3 c89 I have the following source code. And getting a stack dump
Consider the following source code. I have two classes CBar and CFoo. CFoo inherits
I have the following C struct from the source code of a server, and
I have the following source code in main.cpp: #include <iostream> #include <iomanip> int main()

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.