Android ExpandableListActivity Change View at runtime
I am using ExpandableListActivity
i am using
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);
for my activity.
Here i have created Context Menu. Using Context Menu i am deleting the value from database and also form ArrayList
of Child Group
.
I am getting problem is i want to update my ChildView
of Expandable List Activity immediately after deleting values From DataBase
and ArrayList.
i tried using notifyDataSetChanged()
. It do not work as because i am not deleting the value from ExpandableListAdapter itself. I also tried by calling Adapter again after deleting values but it gives two listviews.
// here on select ContextMenu
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item
.ge开发者_开发技巧tMenuInfo();
// 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.
}
Any Help will be appricited.
Thanks in Advance..
Mahaveer
精彩评论