Hi Stanley I guess, wut I am trying to say is, suppose we have this scenario that long press an group item in expandablelist then popup a dialog, click the delete button on the dialog will delete this group item in the expandablelist without meeting this indexoutofboundexception.
Thx Leo On Tuesday, December 9, 2008 7:25:18 PM UTC-8, Stanley.lei wrote: > > Hi all, > > I'm developing an application like management system, and I used the > widget ExpandedListView as the display view. Instead of connecting it > to sqlite database directly, I created two list as the dataset. The > detailed code is as following list: > > private List<Map<String, String>> mGroupType = new > ArrayList<Map<String, String>>(); > private List<List<Map<String, String>>> mGroupInfo = new > ArrayList<List<Map<String, String>>>(); > > private void showGroupView() { > // add layout to the view > LinearLayout layout = new LinearLayout(this); > layout.setOrientation(LinearLayout.VERTICAL); > LayoutParams para = new LayoutParams(LayoutParams.FILL_PARENT, > LayoutParams.FILL_PARENT); > setContentView(layout, para); > > // add expanded list view to layout > mListView = new ExpandableListView(this); > LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, > LayoutParams.FILL_PARENT); > layout.addView(mListView, params); > > // set list view adapter > mListAdapter = new SimpleExpandableListAdapter( > this, > mGroupType, > android.R.layout.simple_expandable_list_item_1, > new String[] {"GROUP_TYPE"}, > new int[] { android.R.id.text1 }, > mGroupInfo, > android.R.layout.simple_expandable_list_item_2, > new String[] {"GROUP_INFO" }, > new int[] { android.R.id.text1 } > ); > mListView.setAdapter(mListAdapter); > mListView.setOnChildClickListener(new OnChildClickListener() { > > public boolean onChildClick(ExpandableListView parent, View v, > int groupPosition, int childPosition, long id) { > return editGroup(groupPosition, childPosition, id); > } > > }); > } > > private void refreshGroupData() { > // fresh mGroupType and mGroupInfo > mGroupType.clear(); > mGroupInfo.clear(); > > fetchAllGroup(mGroupType, mGroupInfo); > > ((BaseExpandableListAdapter) mListAdapter).notifyDataSetChanged(); > } > > When I removed a item in the list, the method refreshGroupData() will > be called. Everything is ok except that when I tried to remove the > last item in the list, an exception was threw with the following trace > info: > > 12-10 11:18:49.738: ERROR/AndroidRuntime(194): Uncaught handler: > thread main exiting due to uncaught exception > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): > java.lang.IndexOutOfBoundsException: Invalid location 0, size is 0 > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > java.util.ArrayList.get(ArrayList.java:350) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.widget.SimpleExpandableListAdapter.getChildrenCount > (SimpleExpandableListAdapter.java:255) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.widget.ExpandableListConnector.refreshExpGroupMetadataList > (ExpandableListConnector.java:489) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.widget.ExpandableListConnector.access$000 > (ExpandableListConnector.java:49) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.widget.ExpandableListConnector$MyDataSetObserver.onChanged > (ExpandableListConnector.java:684) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.database.DataSetObservable.notifyChanged > (DataSetObservable.java:29) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.widget.BaseExpandableListAdapter.notifyDataSetChanged > (BaseExpandableListAdapter.java:56) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.ourdroid.account.GroupSetting.refreshGroupData(GroupSetting.java: > 50) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.ourdroid.account.GroupSetting.deleteGroup(GroupSetting.java:135) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.ourdroid.account.GroupSetting.onOptionsItemSelected > (GroupSetting.java:109) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.app.Activity.onMenuItemSelected(Activity.java:1964) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected > (PhoneWindow.java:708) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java: > 138) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.view.menu.MenuBuilder.performItemAction > (MenuBuilder.java:804) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.view.menu.IconMenuView.invokeItem > (IconMenuView.java:435) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.view.menu.IconMenuItemView.performClick > (IconMenuItemView.java:120) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.view.View.onTouchEvent(View.java:3523) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.widget.TextView.onTouchEvent(TextView.java:4410) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.view.View.dispatchTouchEvent(View.java:3178) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.policy.impl.PhoneWindow > $DecorView.dispatchTouchEvent(PhoneWindow.java:1545) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.view.ViewRoot.handleMessage(ViewRoot.java:1140) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.os.Handler.dispatchMessage(Handler.java:88) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.os.Looper.loop(Looper.java:123) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > android.app.ActivityThread.main(ActivityThread.java:3742) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > java.lang.reflect.Method.invokeNative(Native Method) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > java.lang.reflect.Method.invoke(Method.java:515) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > (ZygoteInit.java:739) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) > 12-10 11:18:49.997: ERROR/AndroidRuntime(194): at > dalvik.system.NativeStart.main(Native Method) > > Could anyone help me on this issue? > > Any help will be appreciated. > > Stanley > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en