Created
February 11, 2015 17:23
-
-
Save anry200/b30436a35a9fe9727942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.database.Cursor; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentStatePagerAdapter; | |
/** | |
* A simple pager adapter. | |
*/ | |
public class CursorPagerAdapter extends FragmentStatePagerAdapter { | |
private Cursor mCursor; | |
public CursorPagerAdapter(FragmentManager fm, Cursor c) { | |
super(fm); | |
mCursor = c; | |
} | |
@Override | |
public Fragment getItem(int position) { | |
if (mCursor.moveToPosition(position)) { | |
Bundle arguments = new Bundle(); | |
final String ARG_ITEM_1_VALUE = mCursor.getString(mCursor.getColumnIndex(COLLUMN)); | |
arguments.putString(ARG_ITEM_1_KEY, ARG_ITEM_1_VALUE); | |
Fragment fragment = new CustomFragment(); | |
fragment.setArguments(arguments); | |
return fragment; | |
} | |
return null; | |
} | |
@Override | |
public int getCount() { | |
if (mCursor != null) { | |
return mCursor.getCount(); | |
} | |
return 0; | |
} | |
public void swapCursor(Cursor cursor) { | |
mCursor = cursor; | |
notifyDataSetChanged(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment