Hi Kostya Thanks for reply.
After changing code like
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 _id, RoomName,
SwitchFullName FROM SwitchTable ORDER BY RoomName",null);
System.out.println ("#######"+groupCursor.getCount());
// Cache the ID column index
mGroupIdColumnIndex =
groupCursor.getColumnIndexOrThrow("_id");
// 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)
{
Cursor groupCursor1 = sampleDB.rawQuery ("SELECT _id,
RoomName, SwitchFullName FROM SwitchTable ORDER BY RoomName",null);
System.out.println ("#######"+groupCursor1.getCount());
return groupCursor1;
}
}
}
It show me the list of room and when I click on any room item then
list of switches appear. But here I have 2 problems:
1. I have a room name as Hall which has 3 switches and second room as
Study room which has 2 switches. But now it shows me Hall 3 times
(because it has 3 switches) and similarly Study room 2 times. I want
it shows Hall only once, I also used DISTINCT for that but it not help
me.
2. In every room it shows all switches means total 5 switches (3
switches from Hall and 2 switches from study room.) I want after
clicking on study room it only shows 2 switches and on clicking on
Hall it shows 3 switches.
Anyone have idea how to achieve this. I think there is problem in
protected Cursor getChildrenCursor(Cursor groupCursor){} method. But I
didn't found it.
Thanks
On Dec 14, 4:32 pm, Kostya Vasilyev <[email protected]> wrote:
> Pramod,
>
> Since your data is in a database, you may want to look at:
>
> http://developer.android.com/reference/android/widget/CursorTreeAdapt...
>
> 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/SimpleCursorTre...
>
> You can see an example of the latter here:
>
> http://developer.android.com/resources/samples/ApiDemos/src/com/examp...
>
> -- 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