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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:54:08+00:00 2026-05-24T03:54:08+00:00

I have an expandable list that contains groups : continents and child : countries.

  • 0

I have an expandable list that contains groups : continents and child : countries. When one country is clicked i want the country to be displayed in a textview on another class.

package com.zeus.eca;

import android.app.ExpandableListActivity;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

public class ListCountries extends ExpandableListActivity implements                 ExpandableListView.OnChildClickListener{

ExpandableListAdapter mAdapter;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAdapter=new MyExpandableListAdapter();;
    setListAdapter(mAdapter);
    getExpandableListView().setOnChildClickListener(this); 
};
@Override
public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {
    // TODO Auto-generated method stub


    return false;
        //return true;
}
    public class MyExpandableListAdapter extends BaseExpandableListAdapter {
    // Sample data set.  children[i] contains the children (String[]) for groups[i].
    private String[] groups ={"Africa","Asia","Europe","North America","South    America","Oceania","Antartica"};
    Resources res = getResources();
    private String[] strAfrica=res.getStringArray(R.array.arrayAfrica);
    private String[] strAsia=res.getStringArray(R.array.arrayAsia);
    private String[] strEurope=res.getStringArray(R.array.arrayEurope);
    private String[] strNAmerica=res.getStringArray(R.array.arrayNAmerica);
    private String[] strSAmerica=res.getStringArray(R.array.arraySAmerica);
    private String[] strOceania=res.getStringArray(R.array.arrayOceania);
    private String[] strAntartica=res.getStringArray(R.array.arrayAntartica);
    private String[][] children = {
            strAfrica,strAsia,strEurope,strNAmerica,strSAmerica,strOceania,strAntartica
    };

    public Object getChild(int groupPosition, int childPosition) {
        return children[groupPosition][childPosition];
    }

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

    public int getChildrenCount(int groupPosition) {
        return children[groupPosition].length;
    }

    public TextView getGenericView() {
        // Layout parameters for the ExpandableListView
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, 55);

        TextView textView = new TextView(ListCountries.this);
        textView.setLayoutParams(lp);
        // Center the text vertically
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        // Set the text starting position
        textView.setPadding(36, 0, 0, 0);
    //    textView.setBackgroundResource(R.drawable.colorWhite);
      //  textView.setTextColor(getResources().getColor(R.color.colorBackground));
        return textView;
    }

    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
            View convertView, ViewGroup parent) {
        TextView textView = getGenericView();
        textView.setText(getChild(groupPosition, childPosition).toString());
        return textView;
    }

    public Object getGroup(int groupPosition) {
        return groups[groupPosition];
    }

    public int getGroupCount() {
        return groups.length;
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
            ViewGroup parent) {

        TextView textView = getGenericView();
        textView.setText(getGroup(groupPosition).toString());
        return textView;

    }
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public boolean hasStableIds() {
        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-24T03:54:09+00:00Added an answer on May 24, 2026 at 3:54 am

    This should work

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {
        String country = (String)mAdapter.getChild(groupPosition, childPosition);
        // update the text view with the country
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of divs that I want to make collapsible/expandable using jQuery's
I'm using Expandable List view. In my app both the group and child have
I'm trying to make a list item expandable. Basically, I want to have a
I want to add an image icon in expandable list view .I have seen
I have one class called Holder (holder.cs) that contain the following: string name; List<String>
Hello i have a simple expandable list activity that was working fine until i
I have a business object that can be edited via PropertyGrid. It contains list
I current have an expandable list that I'd like to be able to search
I have this code for an expandable list, I want to have a checkbox
I have an expandable list view I am using in one xml file which

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.