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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:28:01+00:00 2026-06-10T21:28:01+00:00

I want to populate data in expandableListView from database. Actually all I need to

  • 0

I want to populate data in expandableListView from database. Actually all I need to do is to retrieve all data from a single my
single table, as the first column will be groupName and rest four column will be child, but here i got stuck…
Here is the piece of code that I am trying with.

public class ViewDetail extends Activity{

private ExpandableListView mExpandableListView;
private List<GroupEntity> mGroupCollection;

public void onCreate(Bundle savedInstanceState ){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    prepareResource();
    initPage();
}

private void prepareResource() {

    mGroupCollection = new ArrayList<GroupEntity>();
    DBClass db = new DBClass(ViewDetail.this);
    SQLiteDatabase dc = db.getReadableDatabase();
    Cursor cur = dc.query(true, "db_table", new String[]{"title","_url","username","password","comment"}, null, null, null, null, null, null);
    ContentValues cv = null;
    String _title = "";
    String _url = "";
    String _usrname = "";
    String _pasword = "";
    String _comment = "";

    if(cur.getCount() <= 0){
        Toast.makeText(ViewDetail.this, "empty...Please add.", Toast.LENGTH_LONG).show();
    }else{

        for(int i=0;i<cur.getCount();i++){              

            _title = cur.getString(0);
            _url = cur.getString(1);
            _usrname = cur.getString(2);
            _pasword = cur.getString(3);
            _comment = cur.getString(4);

            GroupEntity ge = new GroupEntity();
            ge.Name = _title;
                GroupItemEntity gi = ge.new GroupItemEntity();
                gi.Name =  _url;//"Child" + j;
                gi.Name =  _usrname;
                gi.Name =  _pasword;
                gi.Name =  _comment;
            mGroupCollection.add(ge);
            cur.moveToNext();   

        }

    }

    cur.close();
    db.close();
    dc.close(); 
    }

}


private void initPage() {

    mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
    ExpandableListAdapter adapter = new ExpandableListAdapter(this,mExpandableListView, mGroupCollection);
    mExpandableListView.setAdapter(adapter);

}

}

public class ExpandableListAdapter extends BaseExpandableListAdapter{

private Context mContext;
private ExpandableListView mExpandableListView;
private List<GroupEntity> mGroupCollection;
private int[] groupStatus;

public ExpandableListAdapter(Context pContext,ExpandableListView pExpandableListView,List<GroupEntity> pGroupCollection) {
    mContext = pContext;
    mGroupCollection = pGroupCollection;
    mExpandableListView = pExpandableListView;
    groupStatus = new int[mGroupCollection.size()];

    setListEvent();
}

private void setListEvent() {

    mExpandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {

                @Override
                public void onGroupExpand(int arg0) {
                    groupStatus[arg0] = 1;
                }
            });

    mExpandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

                @Override
                public void onGroupCollapse(int arg0) {
                    groupStatus[arg0] = 0;
                }
            });
}

@Override
public String getChild(int arg0, int arg1) {
    return mGroupCollection.get(arg0).GroupItemCollection.get(arg1).Name;
}

@Override
public long getChildId(int arg0, int arg1) {
    return 0;
}

@Override
public View getChildView(int arg0, int arg1, boolean arg2, View arg3,ViewGroup arg4) {

    ChildHolder childHolder;
    if (arg3 == null) {

        arg3 = LayoutInflater.from(mContext).inflate(R.layout.list_group_item, null);
        childHolder = new ChildHolder();
        childHolder.title = (TextView) arg3.findViewById(R.id.item_title);
        arg3.setTag(childHolder);
    }else {
        childHolder = (ChildHolder) arg3.getTag();
    }

    childHolder.title.setText(mGroupCollection.get(arg0).GroupItemCollection.get(arg1).Name);
    return arg3;
}

@Override
public int getChildrenCount(int arg0) {
    return mGroupCollection.get(arg0).GroupItemCollection.size();
}

@Override
public Object getGroup(int arg0) {
    return mGroupCollection.get(arg0);
}

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

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

@Override
public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
    GroupHolder groupHolder;
    if (arg2 == null) {

        arg2 = LayoutInflater.from(mContext).inflate(R.layout.list_group,null);
        groupHolder = new GroupHolder();
        groupHolder.img = (ImageView) arg2.findViewById(R.id.tag_img);
        groupHolder.title = (TextView) arg2.findViewById(R.id.group_title);
        arg2.setTag(groupHolder);

    } else {
        groupHolder = (GroupHolder) arg2.getTag();
    }
    if (groupStatus[arg0] == 0) {
        groupHolder.img.setImageResource(R.drawable.group_down);
    } else {
        groupHolder.img.setImageResource(R.drawable.group_up);
    }
        groupHolder.title.setText(mGroupCollection.get(arg0).Name);

    return arg2;
}

class GroupHolder {
    ImageView img;
    TextView title;
}

class ChildHolder {
    TextView title;
}

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

@Override
public boolean isChildSelectable(int arg0, int arg1) {
    return true;
}

}

public class GroupEntity {

public String Name;
public List<GroupItemEntity> GroupItemCollection;

public GroupEntity()
{
    GroupItemCollection = new ArrayList<GroupItemEntity>();
}

public class GroupItemEntity
{
    public String Name;
}

}

  • 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-06-10T21:28:03+00:00Added an answer on June 10, 2026 at 9:28 pm

    Instead of a list to store your data, pull it straight out of the cursor

      Cursor cursor = pContext.getContentResolver().query(DEFAULT_URI, null, null, null, null);
    

    then some examples….

    @Override
    public int getCount() {
        return cursor.getCount();
    }
    
    @Override
    public Object getGroup(int position) {
        cursor.moveToPosition(position);
        String column1 = cursor.getString(COLUMN_1);
        String column2 = cursor.getString(COLUMN_2);
        GroupObject group = new Group(column1, column2);
        return group;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to populate all the data from my database to a table using
I want to populate data from database in to a table view in grouped
I want to populate my database with test data my user and profile models
I want to populate a table form a MYSQL database. I have defined the
I want to populate a drop down menu with a column from a MySQL
I have an UITableView and I want to populate it with data from this
I have a DetailsView control that I want to populate with a data table.
I have table with two SelectOneMenu in row. I need populate data in second
i want populate data in parent window from a popup window. can any one
I am writing a cursor to populate data in new table from main table

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.