Reputation: 1258
In my Activity there is a TabView with 3 Tabs , each tab has a ListView and a Button. When i navigate the tabs using the D-Pad on the emulator there is no problem, but when i use the scroll-wheel(mouse) to navigate the view and then click in the View there is a ForceClose. I think its got something to do with "touchmodechange" but not sure how to handle this. Really appreciate any help...
12-23 19:14:25.352: ERROR/ActivityThread(116): Failed to find provider info for android.server.checkin
12-23 19:18:09.184: ERROR/AndroidRuntime(226): Uncaught handler: thread main exiting due to uncaught exception
12-23 19:18:09.224: ERROR/AndroidRuntime(226): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.widget.ListView.layoutChildren(ListView.java:1428)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.widget.AbsListView.onTouchModeChanged(AbsListView.java:1888)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.view.ViewTreeObserver.dispatchOnTouchModeChanged(ViewTreeObserver.java:591)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.view.ViewRoot.ensureTouchModeLocally(ViewRoot.java:1877)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.view.ViewRoot.ensureTouchMode(ViewRoot.java:1861)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.view.ViewRoot.handleMessage(ViewRoot.java:1652)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.os.Looper.loop(Looper.java:123)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at android.app.ActivityThread.main(ActivityThread.java:4203)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at java.lang.reflect.Method.invoke(Method.java:521)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
12-23 19:18:09.224: ERROR/AndroidRuntime(226): at dalvik.system.NativeStart.main(Native Method)
private void fillData(int tab)
{
Cursor cursor;
Long millis;
String tempstr;
//query table and obtain cursor
if(tab==0)
cursor=dbAdapter.getAllRemindersCursor();
else if(tab==1)
cursor=dbAdapter.getAutoRemindersCursors();
else if(tab==2)
cursor=dbAdapter.getUserRemindersCursors();
else
cursor=dbAdapter.getAllRemindersCursor();
results.clear();
//populate the ArrayList using the cursor
if(cursor!=null)
{
if(cursor.moveToFirst())
{
Log.d("Msg","Cursor at first item");
Log.d("Msg",cursor.getCount()+" items in cursor");
do
{
millis=cursor.getLong(1);
tempstr=cursor.getString(2);
tempstr=" "+tempstr+"\n"+" "+dtf.format(millis);
results.add(tempstr);
category.add(cursor.getInt(4));
Log.d("Msg","message and type items added");
}
while(cursor.moveToNext());
}
}
else
{
Log.d("Msg","Cursor is empty");
}
if(tab==0)
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));
else if(tab==1)
lv2.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));
else if(tab==2)
lv3.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));
else
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));
}
This method is called every time onTabChangedListener is triggered. Other wise there is nothing much else at present in this Activity.
Upvotes: 0
Views: 230
Reputation: 30168
The problem is that you are sharing the same results
List for all of your Adapters. This list is directly referenced inside the adapter, so when you switch a tab you're updating the adapter on all of them (this is why you get an IllegalStateException). Instead of reusing the results variable, simply create a new one inside your filldata method, there's no need (that I can see from the code above) to use the same one. I believe you could have also just used CursorAdapters and not bothered the intermediate List.
Upvotes: 2