IndexOutOfBoundException when I use notifyDataSetChanged

I found my problem in this post Update ExpandableListView with notifyDataSetChanged ()

"every time you update views using setNotifyDatasetChanged, the adapter will loop around the list. And you get a value of zero on the list from the adapter due to the changes made."

I am starting and cannot make the list changes correctly

my sources

public class UrlArrayAdapter extends ArrayAdapter<UrlItem> {

    private LayoutInflater inflater;
    private ListView urlListView1;
    private ArrayList<UrlItem> urlItems1;

    public UrlArrayAdapter(Context context, ListView urlListView,
            ArrayList<UrlItem> urlLists) {
        super(context, urlListView.getId(), urlLists);
        this.urlItems1 = urlLists;
        this.urlListView1 = urlListView;


        inflater = LayoutInflater.from(context);

how to remove an item from a list in urlLists in the base adapter

+3
source share
2 answers

In addition to overriding, public View getView(int position, View view, ViewGroup parent)make sure your class that extends ArrayAdapteroverrides these methods:

public int getCount()
public UrlItem getItem(int position)
public int getPosition(Hold item)
public long getItemId(int position)

, notifyDataSetChanged() getCount() , , . return urlItems1.size();, IndexOutOfBoundException , .

0

: urlList.remove(item_index); , .

, .
remove() , .

, , , remove().

:

public void deleteItem(int numberToDelete) {
    int index=-1;

    // Find the index of numberToDelete
    if(urlLists.contains(numberToDelete)){
        index = urlLists.indexOf(numberToDelete);
    }

    // Delete the number by spefying the index found.
    if(index!=-1){
        urlLists.remove(index);
    }

//...
}
0

All Articles