I\'m an android beginner, trying to learn, and this is my first question, so please excuse me if the question is too simple and please tell me if I\'m using the forum incorr
I extract this from the original Google Samples.
Fragment:
public class IntegerFragment extends Fragment {
int imageResourceId;
int numberSelected;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//change to avoid orientation crash
imageResourceId = getArguments().getInt("param");
numberSelected = getArguments().getInt("number");
}
public static Fragment newInstance(int imageResourceId, int numberSelected) {
IntegerFragment f = new IntegerFragment();
f.imageResourceId = imageResourceId;
f.numberSelected = numberSelected;
return f;
}
FragmentPagerAdapter
public class MyIntegerAdapter1 extends FragmentPagerAdapter {
private Fragment[] fragments;
public MyIntegerAdapter1(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
if (content != null && position < content.length) {
if (fragments[position] == null) {
fragments[position] = IntegerFragment.newInstance(R.drawable.image1, 1);
}
return fragments[position % fragments.length];
}
return null;
etc
Problem over. I found out (from the link below) how a fragment can call a method in its activity. That method is providing the value. I'm not sure it's the best way but it's simple and it works.
Passing data between a fragment and its container activity