android studio: how to update data of a list View made using custom Adapter

459 views Asked by At

I have a list view made using custom Adapter & contains 2 text view in each row, I want to update data of rows , when I long pressed on row.

3

There are 3 answers

0
Mohammad Misbah On

Just update your model object according to the need and call notifyDataSetChanged() inOnLongClickListener or OnItemLongClickListener of ListView. List data will update.

0
Sean Goudarzi On

Go to your custom adapter, and set an OnLongClickListener on the view you return in getView(). In the OnLongClickListener update the array or list you are using and when finished, call notifyDataSetChanged() on the ListView.

0
Nick Titov On

Try this:

listView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                    int pos, long id) {
                adapter.notifyDataSetChanged();
                return true;
            }
        });