Pramod,

Since your data is in a database, you may want to look at:

http://developer.android.com/reference/android/widget/CursorTreeAdapter.html

or its "simple" version, which requires less code, since it's driven by parameters passed into its constructor:

http://developer.android.com/reference/android/widget/SimpleCursorTreeAdapter.html

You can see an example of the latter here:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList2.html

-- Kostya

14.12.2010 14:09, pramod.deore пишет:
For now I had just paste the code which is given at sample code.
Please give me a suggestion what should I write in this method.

On Dec 14, 4:07 pm, "pramod.deore"<[email protected]>  wrote:
Hi I want to display data from database in ExpandableList format. I
have a room table and one switch table I want to display it in
ExpandableList so when I click on room table item then it shows switch
item of that particular room. For this I read code
ExpandableList1.java available in<sdk>/platforms/android-<version>/
samples/...

But still I am facing problem in protected Cursor
getChildrenCursor(Cursor groupCursor) { } method.
Here is my code what should I write into getChildrenCursor.

public class ExpandableList extends ExpandableListActivity
{
     private int mGroupIdColumnIndex;
     SQLiteDatabase sampleDB = null;
     String SAMPLE_DBNAME = "NewHomeAutoDataBase";
         String ROOM_TABLE_NAME = "RoomTable";
         private final String LOADTYPE_TABLE_NAME = "LoadTable";
         String SWITCH_TABLE_NAME = "SwitchTable";

     private String mPhoneNumberProjection[] = new String[] {
                 "RoomName", "SwitchFullName"
     };

     private ExpandableListAdapter mAdapter;

     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME,
MODE_PRIVATE, null);

         Cursor groupCursor = sampleDB.rawQuery ("SELECT RoomName,
SwitchFullName FROM SwitchTable ORDER BY RoomName",null);
         // Cache the ID column index
         mGroupIdColumnIndex =
groupCursor.getColumnIndexOrThrow("RoomName");

         // Set up our adapter
         mAdapter = new MyExpandableListAdapter(groupCursor,
                 this,
                 android.R.layout.simple_expandable_list_item_1,
                 android.R.layout.simple_expandable_list_item_1,
                 new String[] {"RoomName"}, // Name for group layouts
                 new int[] {android.R.id.text1},
                 new String[] {"SwitchFullName"}, // Number for child
layouts
                 new int[] {android.R.id.text1});
         setListAdapter(mAdapter);
     }

     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) {
             // Given the group, we return a cursor for all the
children within that group

             // Return a cursor that points to this contact's phone
numbers
             Uri.Builder builder = People.CONTENT_URI.buildUpon();
             ContentUris.appendId(builder,
groupCursor.getLong(mGroupIdColumnIndex));

builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY);
             Uri phoneNumbersUri = builder.build();

             // The returned Cursor MUST be managed by us, so we use
Activity's helper
             // functionality to manage it for us.
             return managedQuery(phoneNumbersUri,
mPhoneNumberProjection, null, null, null);
         }

     }}

Thanks


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to