Need to understand Horizontal tugging feedback in Google Glass - android

I am just a beginner in Google Glass.
I read about Horizontal tugging feedback here
It says "Many built-in immersions on Glass provide "tugging" feedback when swiping backward and forward don't perform an action. "
Also, we need to add this code to apply the effect :
Helper Class :
public class TuggableView extends CardScrollView {
private final View mContentView;
/**
* Initializes a TuggableView that uses the specified layout
* resource for its user interface.
*/
public TuggableView(Context context, int layoutResId) {
this(context, LayoutInflater.from(context)
.inflate(layoutResId, null));
}
/**
* Initializes a TuggableView that uses the specified view
* for its user interface.
*/
public TuggableView(Context context, View view) {
super(context);
mContentView = view;
setAdapter(new SingleCardAdapter());
activate();
}
/**
* Overridden to return false so that all motion events still
* bubble up to the activity's onGenericMotionEvent() method after
* they are handled by the card scroller. This allows the activity
* to handle TAP gestures using a GestureDetector instead of the
* card scroller's OnItemClickedListener.
*/
#Override
protected boolean dispatchGenericFocusedEvent(MotionEvent event) {
super.dispatchGenericFocusedEvent(event);
return false;
}
/** Holds the single "card" inside the card scroll view. */
private class SingleCardAdapter extends CardScrollAdapter {
#Override
public int getPosition(Object item) {
return 0;
}
#Override
public int getCount() {
return 1;
}
#Override
public Object getItem(int position) {
return mContentView;
}
#Override
public View getView(int position, View recycleView,
ViewGroup parent) {
return mContentView;
}
}
}
Activity Class :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// was: setContentView(R.layout.main_activity);
setContentView(new TuggableView(this, R.layout.main_activity));
}
So my question is : What this effect does and how it affects our application?
Any help will be appreciated.

This code creates the effect of a card "bouncing back", if you would. Similar to how lists in Android allow you to scroll up or down past the end of the list but bounce back to the bottom/top of the list after the user lets go. It gives the illusion of a rubber banding effect.

Related

Android Fragments - Only the original thread that created a view hierarchy can touch its views [duplicate]

This question already has answers here:
Android "Only the original thread that created a view hierarchy can touch its views."
(33 answers)
How do we use runOnUiThread in Android?
(13 answers)
Closed 2 years ago.
this is my main activity:
public class LearnTree extends AppCompatActivity {
private RulesFragment rulesFragment;
private TreeFragment treeFragment;
private PredictionFragment predictionFragment;
TabLayout tabLayout;
ViewPager viewPager;
private Button button;
private static ObjectOutputStream out;
private static ObjectInputStream in;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.learn_tree);
tabLayout=findViewById(R.id.tab_layout);
viewPager= findViewById((R.id.view_pager));
final ViewPagerAdapter viewPagerAdapter= new ViewPagerAdapter(getSupportFragmentManager());
viewPagerAdapter.addFragment(RulesFragment.getInstance(), "TREE RULES");
viewPagerAdapter.addFragment(TreeFragment.getInstance(), "REGRESSION TREE");
viewPagerAdapter.addFragment(PredictionFragment.getInstance(), "PREDICTION");
rulesFragment= (RulesFragment) viewPagerAdapter.getItem(0);
treeFragment= (TreeFragment) viewPagerAdapter.getItem(1);
predictionFragment= (PredictionFragment) viewPagerAdapter.getItem(2);
viewPager.setAdapter(viewPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
LearnTree.PrimeThread p=new LearnTree.PrimeThread();
p.start();
}
private class PrimeThread extends Thread {
public void run() {
out= SocketObject.getOut();
in = SocketObject.getIn();
// print rules
rulesFragment.setText((String)in.readObject());
//print tree
treeFragment.setText((String)in.readObject());
}
}
}
And this is one my 3 fragments, the other 2 are almost the same:
public class RulesFragment extends Fragment {
// Store instance variables
private String title;
private int page;
private TextView rulesView;
public static RulesFragment getInstance() {
RulesFragment rulesFragment = new RulesFragment();
return rulesFragment;
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.rules_fragment, container, false);
rulesView= (TextView) view.findViewById(R.id.textview_treerules);
rulesView.setMovementMethod(new ScrollingMovementMethod());
return view;
}
public void setText(String text){
rulesView.setText(text);
}
}
When executing rulesFragment.setText((String)in.readObject()); I get this error: Only the original thread that created a view hierarchy can touch its views
That's because I created the textview in onCreateView but I'm editing it in setText right? The problem is that I need to edit that text multiple times during the program execution and I cannot transfer part of my code in onCreateView (to make it run like a separate thread i guess?) because I need to retrieve input from the Socket sequentially.
Is there another way to do this?
Moreover let's say I have a Spinner in the third fragment and a button "Send". When the user hits Send I'm supposed to reset every textview in each fragment to empty and I need to restart the execution in PrimeThread in LearnTree class. How can I do this? Is there a way to detect the onClick event of send button from the mainactivity?
The previous answer is very complete.
However, you could try by calling the:
Device.BeginInvokeOnMainThread(
() => { lblStatus.Text = "Updating..."; }
);
To answer your main issue, what is happening is that the thread that creates the view is the Main UI thread. For this reason, whenever you want to change something on the UI from a different thread (in your case the PrimeThread), you should execute the functions by using runOnUiThread.
This means in your code you should have:
String rules = (String)in.readObject()
String tree = (String)in.readObject()
requireActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
// print rules
rulesFragment.setText(rules);
//print tree
treeFragment.setText(tree);
}
});
For your last question about having a listener for a button click, you can do it like this:
Button buttonY = (Button)findViewById(R.id.buttonYName);
// Register the onClick listener with the implementation above
buttonY.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
(LearnTree)getActivity().primeThread.start(); // Assuming this is executed in the context of a Fragment
}
});
If you want to restart the thread in the LearnTree Activity, you need to store the thread in a class variable:
public LearnTree.PrimeThread primeThread;
Or declare it as private and have a getter/setter, it's up to you.
Also, you should create your ViewPagerAdapter like this, otherwise you will get crashes:
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
#Override
public Fragment getItem(int position) {
if(position == 0) return new RulesFragment();
if(position == 1) return new TreeFragment();
if(position == 2) return new PredictionFragment();
throw new IllegalStateException("Unexpected position " + position);
}
#Override
public int getCount() {
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
if(position == 0) return "TREE RULES";
if(position == 1) return "REGRESSION TREE";
if(position == 2) return "PREDICTION";
throw new IllegalStateException("Unexpected position " + position);
}
}
To get a reference to a Fragment created by a ViewPager, use the following findFragmentByTag scheme:
Fragment fragment = supportFragmentManager.findFragmentByTag("android:switcher:" + viewPager.getId() + ":" + fragmentPosition)

Getting data from fragments on button click in host activity

So I'm creating this app that allows users to search for recipes by ingredients, categories, and preparation time.
Initially, I had 3 activities:
IngredientActivity, where the user chooses ingredients they have.
CategoryActivity, where they can choose multiple food categories from a list.
TimeActivity, which allows users to choose maximum preparation time.
However, it was such a hassle this way as I had to pass the data the user chose with an Intent to the next activity with a next button, and it was a mess always getting and adding extras until I got to the last activity, plus I wanted to be able to move freely between the 3 "pages", and not be restricted to going through them one by one.
This didn't seem efficient to me so I decided to change those activities into fragments and use a ViewPager to display them in tabs in a host activity (MainActivity), but it seems it's a different kind of hassle now.
I have a Search button in the MainActivity, and I'm having difficulty getting the data the user chose from all 3 fragments all at once when the Search button is clicked. I read about interfaces, but I'm not sure if it's the solution. I thought maybe I could define an OnSearchClickListener interface in all 3 fragments, but can I implement one interface for 3 fragments, with each fragment returning different data?
Did I make a mistake transitioning to fragments? However, it seemed the most efficient way to do it... How can I get all the data from the fragments when the search button is clicked?
Note: updated upon clarifications in comments
I would do the following:
In each of the three fragments, implement method getSearchCriteria, with each returning value specific to that fragment.
Implement one OnClickListener for the search button - at the activity level.
Inside that listener, call getSearchCriteria on each of the fragments - and do whatever you need to do with all the collated results, something like this:
findViewById(R.id.button_search).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
List<String> ingredients = ingredientFragment.getSearchCriteria();
List<String> categories = categoryFragment.getSearchCriteria();
int maxMinutes = timeFragment.getSearchCriteria();
// now you have all three things together - do what you need to with them
}
});
If you notify the MainActivity every time the criteria is updated, you can update their respective criterias and have them available to use when searching (see onSearchClicked)
IngredientFragment.java
public class IngredientFragment extends Fragment {
EditText editText;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_ingredient, container, false);
editText = (EditText)view.findViewById(R.id.edit_text);//assuming user type in the criteria in an edit box
return view;
}
public void onClick(View view){//user interaction to signal criteria updated. Replace this with onItemClickListener etc, if you are using ListView
if (mListener != null) {
mListener.onIngredientCriteriaUpdated(String.valueOf(editText.getText()));
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnIngredientFragmentListener) {
mListener = (OnIngredientFragmentListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnIngredientFragmentListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnIngredientFragmentListener {
// TODO: Update argument type and name
void onIngredientCriteriaUpdated(String criteria);
}
}
CategoryFragment.java
public class CategoryFragment extends Fragment {
EditText editText;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_category, container, false);
editText = (EditText)view.findViewById(R.id.edit_text);//assuming user type in the criteria in an edit box
return view;
}
public void onClick(View view){//user interaction to signal criteria updated. Replace this with onItemClickListener etc, if you are using ListView
if (mListener != null) {
mListener.onCategoryCriteriaUpdated(String.valueOf(editText.getText()));
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnCategoryFragmentListener) {
mListener = (OnCategoryFragmentListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnCategoryFragmentListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnCategoryFragmentListener {
// TODO: Update argument type and name
void onCategoryCriteriaUpdated(String criteria);
}
}
TimeFragment.java
public class TimeFragment extends Fragment {
EditText editText;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_category, container, false);
editText = (EditText)view.findViewById(R.id.edit_text);//assuming user type in the criteria in an edit box
return view;
}
public void onClick(View view){//user interaction to signal criteria updated
if (mListener != null) {
mListener.onTimeCriteriaUpdated(String.valueOf(editText.getText()));
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnTimeFragmentListener) {
mListener = (OnTimeFragmentListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnTimeFragmentListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnTimeFragmentListener {
// TODO: Update argument type and name
void onTimeCriteriaUpdated(String criteria);
}
}
MainActivity.java (partial code)
public class MainActivity extends AppCompatActivity implements
IngredientFragment.OnIngredientFragmentListener,
CategoryFragment.OnCategoryFragmentListener,
TimeFragment.OnTimeFragmentListener {
private String ingredientCriteria;
private String categoryCriteria;
private String timeCriteria;
:
:
:
#Override
public void onIngredientCriteriaUpdated(String criteria) {
ingredientCriteria = criteria;
}
#Override
public void onCategoryCriteriaUpdated(String criteria) {
categoryCriteria = criteria;
}
#Override
public void onTimeCriteriaUpdated(String criteria) {
timeCriteria = criteria;
}
public void onSearchClicked(View view){//handler for your search button
//do search using value of ingredientCriteria + categoryCriteria + timeCriteria
}
}

How to add a splash screen to my android tv app ?

does anyone know how to add a splash screen to an Android TV App ? what is making it hard for me is that the main activity should have Theme.Leanback in order to be accepted in the google play , and to have a splash screen you need your own style/theme. So how to do this ?
You can customise Leanback's OnboardingFragment slightly to display it as splash screen. OnboardingFragment allows you to add on-boarding steps but if you don't need them you can just set setLogoResourceId inside onCreateView.
Note that it crashes if you keep page count to zero so keep page count to one and splash duration greater than LOGO_SPLASH_PAUSE_DURATION_MS = 1333 otherwise a page with "Get Started" button will be displayed.
The idea is to use onboarding fragment with just a splash screen initially and add on-boarding steps as your application grows.
OnboardingFragment
public class OnboardingFragment extends android.support.v17.leanback.app.OnboardingFragment {
private static final long SPLASH_DURATION_MS = 2000;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
view.setBackgroundColor(Color.RED);
}
setLogoResourceId(R.drawable.logo);
Handler handler = new Handler();
Runnable runnable = new Runnable() {
#Override
public void run() {
onFinishFragment();
}
};
handler.postDelayed(runnable, SPLASH_DURATION_MS);
return view;
}
#Override
protected void onFinishFragment() {
super.onFinishFragment();
// Our onboarding is done
// Let's go back to the MainActivity
getActivity().finish();
}
#Override
protected int getPageCount() {
return 1;
}
#Override
protected String getPageTitle(int pageIndex) {
return null;
}
#Override
protected String getPageDescription(int pageIndex) {
return null;
}
#Nullable
#Override
protected View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container) {
return null;
}
#Nullable
#Override
protected View onCreateContentView(LayoutInflater inflater, ViewGroup container) {
return null;
}
}
OnboardingActivity
/*
* OnboardingActivity for OnboardingFragment
*/
public class OnboardingActivity extends Activity {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onboarding);
}
}
onboarding.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/onboarding_fragment"
android:name="com.example.android.tvleanback.ui.OnboardingFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Declare OnboardingActivity inside AndroidManifest
<activity android:name=".ui.OnboardingActivity"
android:enabled="true"
android:exported="true"
android:theme="#style/Theme.Leanback.Onboarding" />
Start OnboardingActivity from MainActivity's onCreate
Visit following site and copy code from there and make changes accorting to your activity name,img name.also make changes on your manifest to start app with spash screen
http://www.coderefer.com/android-splash-screen-example-tutorial/

Open fullscreen SupportMapFragment on Double-Tap

I'm using the Google Maps Android API v2 and I want to be able to open as fullscreen a small map (= SupportMapFragment in my view) on tap (or double tap).
Is this technically possible? If yes, how to achieve it?
Thanks in advance.
Yes, that is definitely possible.
You could for example have a Button, and upon pressing the Button the MapFragment / SupportMapFragment will be added to a container layout inside your Activity's layout file.
Inside the onClick method of your Button you add the Fragment to the container layout:
YourMapFragment f = new YourMapFragment();
getFragmentManager().beginTransaction().add(R.id.container_layout, f).commit();
In this case, I would recommend that "container_layout" is an empty FrameLayout, used as a placeholder in your Activity's layout file. This is where the Fragment will then appear.
If you really want to use Taps, this is how you can recognize for example a double-tap:
You will need an interface that the class that needs to recognize the
gesture has to implement
You need a custom TouchManager, that will use callbacks to the interface to interpret the gesture
The interface:
public interface GestureInterface {
/**
* returns the recognized gesture from the touchmanager
* and enables the user of the interface to react to the gesture (or not)
* #param gesture e.g. TouchManager.SWIPE_LEFT
*/
public void onGestureRecognized(int gesture);
}
The TouchManager:
public class TouchManager extends GestureDetector.SimpleOnGestureListener {
public static final int DOWN = 1;
public static final int DOUBLE_TAP = 2;
/** the class that initialized the gesture-recognizer and will be notified upon gestures made by the user */
private GestureInterface caller;
/**
* constructor
* #param the caller that implements the gestureinterface
*/
public TouchManager(GestureInterface caller) {
this.caller = caller;
}
/**
* you need this shit to return true, otherwise gestures wont work
*/
#Override
public boolean onDown(MotionEvent e) {
caller.onGestureRecognized(DOWN);
return true;
}
#Override
public boolean onDoubleTap(MotionEvent e) {
caller.onGestureRecognized(DOUBLE_TAP); // callback
return true;
}
}
And inside your Activity (or Customview or wherever you want to recognize the gesture): (In this case tapping on the Activity will call the Touchmanager.
public class YourActivity extends Activity implements GestureInterface {
private GestureDetector gd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayout);
// initialize the touch manager
gd = new GestureDetector(this, new TouchManager(this));
}
#Override
public boolean onTouchEvent(MotionEvent event) {
return gd.onTouchEvent(event);
}
#Override
public void onGestureRecognized(int gesture) {
// react to callbacks
switch (gesture) {
case TouchManager.DOUBLE_TAP:
// do something
YourMapFragment f = new YourMapFragment();
getFragmentManager().beginTransaction().add(R.id.container_layout, f).commit();
break;
}
}
}
Wherever you want to recognize the gesture, you return GestureDetector.onTouchEvent(...).

multiple layout viewpager with one fragment

I must clear that I am looking for an example or answer where I can use various differnt layout designs in a viewpager and the data in all the pages would be dynamic and all pages can be interacted by the user.
My Use Case and current approach towards the problem :
So I have got 8 different types of question types and so I have created layouts for all of them. Also I the data in the views for these layouts has to be populated via java Map that has fetched data from the sqlite DB.
But a test may contain 25 questions with different layouts out of the above 8. And for all these 25 questions I want to use a Viewpager and a Fragment that will return the required layout based on the passed question type value out of my java map.
My apporach towards this :
I have created an activity and have inflated it with a viewpager layout :
R.layout.practice_pager
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/test_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
*Activity Edited code *
public class TestActivity extends FragmentData implements FragmentData{
FragmentManager manager=getSupportFragmentManager();
private ViewPager mViewPager;
private MyFragmentPagerAdapter mMyFragmentPagerAdapter;
int PAGE_COUNT = 0;
GrePracticeTestRecord p=new GrePracticeTestRecord();
private HashMap<Integer, GrePracticeResultRecord> mPracResultMap;
public static int fragmentToReturn=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.practice_pager);
mViewPager = (ViewPager) findViewById(R.id.test_container);
//This function is called to fetch the data from sqlite db and fill the map with data
LoadingTestView();
PAGE_COUNT=mPracRecordMap.size();
initPager();
}
//here I initialize the pager and set the adapter to it
public void initPager()
{
p.setQUES(mPracRecordMap.get(1).getQUES());
p.setEXPL(mPracRecordMap.get(1).getEXPL());
fragmentToReturn=Integer.parseInt(mPracRecordMap.get(1).getQTYPE());
setData(p);
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),fList);
mViewPager.setAdapter(mMyFragmentPagerAdapter);
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageSelected(int arg0) {
mMyFragmentPagerAdapter.notifyDataSetChanged();
p.setQUES(mPracRecordMap.get(mViewPager.getCurrentItem()+1).getQUES());
p.setEXPL(mPracRecordMap.get(mViewPager.getCurrentItem()+1).getEXPL());
setData(p);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
#Override
public void setData(GrePracticeTestRecord p) {
// TODO Auto-generated method stub
}
#Override
public GrePracticeTestRecord getData() {
// TODO Auto-generated method stub
return p;
}
}
My Adapter Edited code
public class MyFragmentPagerAdapter extends FragmentStatePagerAdapter{
private List<Fragment> fragments;
public MyFragmentPagerAdapter(FragmentManager fm,List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
/** This method will be invoked when a page is requested to create */
#Override
public Fragment getItem(int position) {
System.out.println("value of position "+position);
return this.fragments.get(position);
}
/** Returns the number of pages */
#Override
public int getCount() {
return this.fragments.size();
}
#Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return MyFragmentPagerAdapter.POSITION_NONE;
}
}
Interface FragmentData
public interface FragmentData {
public void setData(GrePracticeTestRecord p);
public GrePracticeTestRecord getData();
}
TestFragment Edited code
public class TestFragment extends Fragment {
AnswerEnterListener callBack;
FragmentData fD;
Button submitAnswer;
EditText userAnswer;
TextView qText,expl;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.qtype1, container, false);
}
public interface AnswerEnterListener
{
public void onInputAnswer(String ans);
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
callBack=(AnswerEnterListener) activity;
fD=(FragmentData) activity;
} catch (Exception e) {
// TODO: handle exception
}
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
qText=(TextView) getActivity().findViewById(R.id.question_text);
expl=(TextView)getActivity().findViewById(R.id.explanation_text);
qText.setText(Html.fromHtml(fD.getData().getQUES()));
expl.setText(Html.fromHtml(fD.getData().getEXPL()));
}
}
Similar to TestFragment , I have not the other fragments too. Each for a layout type.
Issues :
The first layout is repeated two times at the first time , and also when I swipe back then the position of data is misplaced.
Is this the right approach, I have been suggested by someone that you should use three fragments and update the left and right fragments with data , but this actually bounced off me. Can anyone share a good example of it or a blog.
I must clear that I am looking for an example or answer where I can
use various differnt layout designs in a viewpager and the data in all
the pages would be dynamic and all pages can be interacted by the
user.
This should be quite easy to make but you seem to have complicated this a lot. You need to do something like this:
Get the data from the database with the LoadingTestView(); function.
Initialize the ViewPager and set it's adapter. The adapter will return the proper fragment instance in the getItem() method, based on whatever criteria you have.
In the fragments, retrieve the data from the activity which should expose the data through some method.
I've made a simple example that you can find here.

Categories

Resources