Reputation: 2472
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
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