If changes query as
Cursor groupCursor = sampleDB.rawQuery ("SELECT DISTINCT
RoomName,_id, SwitchFullName FROM SwitchTable GROUP BY
RoomName",null);
and getChikldrenCursor as
protected Cursor getChildrenCursor(Cursor groupCursor)
{
Cursor groupCursor1 = sampleDB.rawQuery ("SELECT DISTINCT
RoomName,_id, SwitchFullName FROM SwitchTable GROUP BY
RoomName",null);
System.out.println ("#######"+groupCursor1.getCount());
return groupCursor1;
}
Then it shows me 2 rooms. But switches are not shows correctly. Here
it shows 2 switches in each room and in actually room 1 Hall contains
3 and room 2 Study contains 2 switches.
On Dec 15, 10:52 am, "pramod.deore" <[email protected]> wrote:
> Now when I changes cursor as
> Cursor groupCursor = sampleDB.rawQuery ("SELECT DISTINCT RoomName FROM
> SwitchTable ",null);
> then it shows 2 rooms(i.e Hall and study room) but when i click on any
> item then it throgh exception . my logact is :
>
> 12-15 11:16:56.612: ERROR/CursorWindow(893): Bad request for field
> slot 0,-1. numRows = 2, numColumns = 1
> 12-15 11:16:56.642: DEBUG/AndroidRuntime(893): Shutting down VM
> 12-15 11:16:56.652: WARN/dalvikvm(893): threadid=3: thread exiting
> with uncaught exception (group=0x4001b188)
> 12-15 11:16:56.663: ERROR/AndroidRuntime(893): Uncaught handler:
> thread main exiting due to uncaught exception
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893):
> java.lang.IllegalStateException: get field slot from row 0 col -1
> failed
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.database.CursorWindow.getLong_native(Native Method)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.database.CursorWindow.getLong(CursorWindow.java:380)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:
> 108)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.CursorTreeAdapter
> $MyCursorHelper.getId(CursorTreeAdapter.java:435)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.CursorTreeAdapter.getGroupId(CursorTreeAdapter.java:
> 190)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:
> 422)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:745)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:
> 1081)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.AbsListView.onTouchEvent(AbsListView.java:2061)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.widget.ListView.onTouchEvent(ListView.java:3234)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.view.View.dispatchTouchEvent(View.java:3709)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> com.android.internal.policy.impl.PhoneWindow
> $DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:
> 1107)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.app.Activity.dispatchTouchEvent(Activity.java:2061)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> com.android.internal.policy.impl.PhoneWindow
> $DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.os.Handler.dispatchMessage(Handler.java:99)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.os.Looper.loop(Looper.java:123)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> android.app.ActivityThread.main(ActivityThread.java:4363)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> java.lang.reflect.Method.invokeNative(Native Method)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> java.lang.reflect.Method.invoke(Method.java:521)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> com.android.internal.os.ZygoteInit
> $MethodAndArgsCaller.run(ZygoteInit.java:860)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> 12-15 11:16:56.742: ERROR/AndroidRuntime(893): at
> dalvik.system.NativeStart.main(Native Method)
>
> On Dec 15, 9:19 am, "pramod.deore" <[email protected]> wrote:
>
> > 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;
>
> ...
>
> read more »
--
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