Paolo
Paolo

Reputation: 2472

Listview and array adapter and remove

I created an adapter

public class MyArrayAdapter extends ArrayAdapter<Watch> 

overriding

public MyArrayAdapter(Context context, List<Watch> values){     
    super(context, android.R.layout.simple_list_item_1, values);        
    this.context = context;
}

and

private View createOneView(){
...
}

Then i do

 MyArrayAdapter myAdapter = new MyArrayAdapter(this, getAllWatches());
 ... //DO some stuff here
 myAdapter.remove(getAllWatches().get(2));
 myAdapter.notifyDataSetChanged();

The watch is still not removed. I suspect that objects are removed only if ther are == and not .equal(), or am I just missing something more trivial?

Upvotes: 0

Views: 308

Answers (1)

Paolo
Paolo

Reputation: 2472

myAdapter.getPosition(getAllWatches().get(2)) return -1, so the problem is the object is not found. ArrayAdapater uses indeed .equals() method. Implementing it in the appropriate way (comparingfields) everything works smoothly.

Upvotes: 2

Related Questions