Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : How to Refresh list upon item deletion in customized SimpleAdapter

May i know how to refresh the ListView item after i have remove a map list item in customized SimpleAdapter ?

I have successfully implement the delete list item with list.remove(position), but when I have tried to called list.notifyAll() function but it gave me error message like " java.lang.IllegalMonitorStateException: object not locked by thread before notifyAll()".

I hope you can help me. Here is the code for custom SimpleAdapter.

public class DeleteAdapter extends SimpleAdapter {

    Context context;
    List<? extends Map<String, ?>> list;
    int resource;
    String[] from;
    int[] to;

    public FDeleteAdapter(Context context, List<? extends Map<String, ?>> data,
            int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);

        this.context = context;
        this.list = data;
        this.resource = resource;
        this.from = from;
        this.to = to;
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final View row = super.getView(position, convertView, parent);

        final Button delete = (Button) row.findViewById(R.id.deletebut);
        final TextView title = (TextView) row.findViewById(R.id.label);

        delete.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {

                deleteDialog xdialog = new deleteDialog(context, "Delete? ", position) {

                    @Override
                    public boolean onOkClicked() {

                        list.remove(position);
                        list.notifyAll();

                        return true;
                    }
                };
                xdialog.show();
            }
        });

        return row;
    }
};

Thank you in advance for your help.

like image 422
johnteow Avatar asked Dec 05 '11 19:12

johnteow


1 Answers

You should call Adapter's notifyDataSetChanged() function, not notifyAll() on list.

like image 97
inazaruk Avatar answered Oct 23 '22 23:10

inazaruk