I'm developing an app that shows the user a whole bunch of flash cards using a ViewPager. My problem is as follows - I have a custom PagerAdapter I made to handle cursors and get a whole bunch of data from my database and put it into a view. I want to add an option to delete a card but I'm not sure how to go about doing it. Here's my PagerAdapter code. Not too sure where to go from here.
public class CardCursorPagerAdapter extends PagerAdapter {
private Cursor cursor;
private LayoutInflater inflater;
public CardCursorPagerAdapter(Context context, Cursor cursor){
this.cursor = cursor;
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void swapCursor(Cursor cursor){
this.cursor = cursor;
}
@Override
public void destroyItem(View view, int position, Object object) {
((ViewPager) view).removeView((LinearLayout) object);
}
@Override
public int getCount() {
if (cursor == null) {
return 0;
} else {
return 1000;
}
}
@Override
public Object instantiateItem(View view, int position) {
LinearLayout layout;
int position2 = position;
if (position == 0){
layout = (LinearLayout) inflater.inflate(R.layout.activity_slide_info, null);
} else {
position2++;
position2 = position2 % cursor.getCount();
cursor.moveToPosition(position2);
layout = (LinearLayout) inflater.inflate(R.layout.activity_card, null);
TextView cardTitle = (TextView) layout.findViewById(R.id.card_title);
TextView cardExample = (TextView) layout.findViewById(R.id.card_example);
TextView cardDefinition = (TextView) layout.findViewById(R.id.card_definition);
cardTitle.setText(cursor.getString(cursor.getColumnIndex(FlashCardTable.COLUMN_TITLE)));
cardExample.setText(cursor.getString(cursor.getColumnIndex(FlashCardTable.COLUMN_SENTENCE)));
cardDefinition.setText(cursor.getString(cursor.getColumnIndex(FlashCardTable.COLUMN_DEFINITION)));
}
((ViewPager) view).addView(layout);
return layout;
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
}