Reputation: 55
I am trying to make an app with card swipe like tinder. I have a Texview with some text on it and when I swipe next card has another text and so on. What I also want to do is when i click on a button to remove the card on screen and go to the next one. I am removing first String from a list and call adapter.notifyDataSetChange. The problem is that the text on screen stays the same even tough the string is removed every time I click. I even Loged the values in adapter and they are changed and number of cards are dropping but the text on the screen stays the same.
When I download data in onResponse I call, flingContainer is custom view that extends adapterView
myAppAdapter = new MyAppAdapter(list, this);
flingContainer.setAdapter(myAppAdapter);
When I click the button I call
list.remove(0);
myAppAdapter.notifyDataSetChanged();
This is my adapter
public class MyAppAdapter extends BaseAdapter {
public List<String> parkingList;
public Context context;
private MyAppAdapter(List<String> apps, Context context) {
this.parkingList = apps;
this.context = context;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = getLayoutInflater();
rowView = inflater.inflate(R.layout.item, parent, false);
viewHolder = new ViewHolder();
ViewHolder.background = (FrameLayout) rowView.findViewById(R.id.background);
viewHolder.cardImage = (TextView) rowView.findViewById(R.id.cardImage);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.cardImage.setText(parkingList.get(position));
return rowView;
}
}
Upvotes: 1
Views: 192
Reputation: 16587
You call list.remove(0)
so it's just remove first index from your list not from your Adapter. In fact you pass copy of list into your Adapter and they're different; So to make it work In addition to call list.remove(0) add removeItem()
in your adapter:
public void removeItem(int index){
parkingList.remove(index);
notifyDataSetChange();
}
Upvotes: 1