Search code examples
androidlistviewadapterexpandablelistviewbaseadapter

Refresh List View programmatically within Adapter


How to refresh Child List within Expandable List View

I am using following code to delete child list item, but unable to refresh Child Item List.

public class ListAdapter extends BaseExpandableListAdapter {

private Context _context;
private List<String> _listDataHeader;
private HashMap<String, List<String>> _listDataChild;
private DBAdapter mydb;

    public SyncExpandablePendingListAdapter(Context context, List<String> listDataHeader,
                                        HashMap<String, List<String>> listChildData) {
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}

@Override
public Object getChild(int groupPosition, int childPosititon) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .get(childPosititon);
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
}

@Override
public View getChildView(final int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {

    ....

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.sync_pending_list_item, null);
    }

    ....

    btnDelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                Log.d("oldList:", _listDataChild.toString());

                mydb.DeleteECRecord(data2);
                _listDataChild.remove(childPosition);
                notifyDataSetChanged();

                Log.d("newList:", _listDataChild.toString());

    });

}

.............

}

Actually, I am not getting where I have to make the change ? What exactly I have missed ? :

Please let me know Where I am doing MISTAKE ? What I am MISSING ?


Solution

  • You removed that entry from your database, but didn't remove it from the HashMap. Remove it from HashMap too and then call notifyDataSetChanged().