mercredi 22 juillet 2015

android expandable list view approach to have chlids size not fixed from database

I Just Wanted to have a Expandable listview from the values in sqlite Iam getting all the headers correctly and a single child correctly Now what i need is Expandable listviews childs are not fixed for some values it may be 3 for some it may be 2 Here by having adapter code please help me

private void fillData() {

        Cursor mGroupsCursor;
        databasehelperhome mHelper = new databasehelperhome(this);

        mGroupsCursor = mHelper.fetchGroup();
        startManagingCursor(mGroupsCursor);
        mGroupsCursor.moveToFirst();

        ExpandableListView elv = (ExpandableListView) findViewById(android.R.id.list);

        madapter = new MyExpandableListAdapter(mGroupsCursor, Home.this,
            R.layout.list_group,                     // Your row layout for a group
            R.layout.list_item,                     // Your row layout for a child
            new String[] { "Site_Name" },                      // Field(s) to use from group cursor
            new int[] { R.id.lblListHeader },                 // Widget ids to put group data into
            new String[] { "Child" },                   // Field(s) to use from child cursors
            new int[] {R.id.lblListItem }
            );          // Widget ids to put child data into

        elv.setAdapter(madapter);                           // set the list adapter.
        }

    public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {
        public MyExpandableListAdapter(Cursor cursor, Context context,int groupLayout, 
            int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom, 
            int[] childrenTo)
        {
                super(context, cursor, groupLayout, groupFrom, groupTo,
                      childLayout, childrenFrom, childrenTo);
            }
        @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) {

            Cursor childCursor = mHelper.fetchChildren(groupCursor.getString(groupCursor.getColumnIndex("Site_Name")));            
            startManagingCursor(childCursor);
            childCursor.moveToFirst();

            return childCursor;
        }

        }

Aucun commentaire:

Enregistrer un commentaire