I found only one similiar question and it didn't help me. I hope you can help me, because I'm stuck.
This is my custom adapter (only the relevant part):
MyExpandableListAdapter
:
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
//...
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
ChildInfo childInfo = (ChildInfo) getChild(groupPosition, childPosition);
if (view == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.prisustva_detaljno_child_row,
null);
}
Button delete = (Button) view.findViewById(R.id.delete);
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout Rl = (RelativeLayout) v.getParent();
TextView id = (TextView) Rl.findViewById(R.id.id_prisustvo);
PrisustvaAdapter deleteByID = new PrisustvaAdapter(context);
deleteByID.openToWrite();
deleteByID.openToRead();
deleteByID.deleteID(id .getText().toString());
deleteByID.close();
Toast.makeText(context, "Successfully deleted!",
Toast.LENGTH_LONG).show();
}
});
// ...
return view;
}
// ...
}
Like you can see I have a button in every child row of my ExpandableListView
. When I click on that button it triggers the deletion process in my database, as you can also see I have to do the deletion from within my adapter, because only there I can create the click event for the button inside the child row. I want to know how can I refresh my ExpandableListView
when I remove the data from database? Do I have to do it from inside the adapter? If not, what’s the alternative?
P.S: If you guys need more code, please let me know.
I can't be sure without seeing the rest of your code (how you instantiate your BaseExpandableAdapter
) but calling notifyDatasetChanged()
at the end of your onClick()
method should do the trick.