我正在使用ExpandableListActivity
我正在使用
SimpleExpandableListAdapter(Context context, List<? extends Map<String, ?>> groupData, int groupLayout, String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>> childData, int childLayout, String[] childFrom, int[] childTo);
为我的活动。在这里,我创建了上下文菜单。使用上下文菜单我正在从数据库中删除值ArrayList
以及Child Group
. 我遇到的问题是我想ChildView
在删除值后立即更新我的可扩展列表活动DataBase
,ArrayList.
我尝试使用notifyDataSetChanged()
. 它不起作用,因为我没有从 ExpandableListAdapter 本身删除值。我也尝试在删除值后再次调用适配器,但它提供了两个列表视图。
// here on select ContextMenu
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item
.getMenuInfo();
// Getting positions of Group and child from Expandable ListView
int groupPos = 0, childPos = 0;
int type = ExpandableListView
.getPackedPositionType(info.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
groupPos = ExpandableListView
.getPackedPositionGroup(info.packedPosition);
childPos = ExpandableListView
.getPackedPositionChild(info.packedPosition);
}
db.openConnection(this);
View v = info.targetView;
TextView tv = (TextView) v.findViewById(R.id.grp_child);
String string = (String) tv.getText();
// Here I delete the value from DataBase onClik of Context Menu.
if (item.getItemId() == 0) {
final String where = "title=?";
final String[] args = new String[] { string };
database.delete(tableData, where, args);
}
// Here I delete the value from ArrayList onClik of Context Menu.
//result1 is ArrayList<ArrayList<HashMap<String,String>>>();
result1.get(groupPos).get(childPos);
result1.remove(result1.get(groupPos).get(childPos));
Log.e("Search", "is" + result1.get(groupPos).get(childPos));
/*expListAdapter.notifyDataSetChanged();*/
db.closeConnection();
return super.onContextItemSelected(item);
// when i delete form both arraylist and database i want to update //ListView immidiately.
}
任何帮助都会被告知。
提前致谢..
马哈维尔