@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
public class SpaFragment extends Fragment {
public SpaFragment(){}
private SpaList mSpa;
private TabHost tabs;
private View rootView;
private ViewPager pager;
private PagerAdapter pagerAdapter;
public void setSpa(SpaList s)
{
mSpa=s;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.spa_tab_fragment, container, false);
FragmentManager f = ((FragmentActivity) getActivity()).getSupportFragmentManager();
pagerAdapter = new MyPagerAdapter( f );
pager = (ViewPager) rootView.findViewById(R.id.pager);
pager.setAdapter(pagerAdapter);
pagerAdapter.notifyDataSetChanged();
Log.d(""+mSpa.getSpaName(),"");
return rootView;
}
private class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public CharSequence getPageTitle(int position) {
Resources res = getResources();
String[] title = res.getStringArray(R.array.title_spa_viewpager_array);
return title[position];
}
@Override
public android.support.v4.app.Fragment getItem(int pos) {
switch(pos) {
case 0: return FirstFragment.newInstance(mSpa.getSpaName());
case 1: return SecondFragment.newInstance(mSpa.getSpaAddr());
case 2: return SecondFragment.newInstance(mSpa.getCityEngName());
default: return FirstFragment.newInstance(mSpa.getSpaPhone());
}
}
@Override
public int getCount() {
return 3;
}
}
}
public class PagerAdapter extends FragmentPagerAdapter
{
private Fragment[] fragments;
private String[] titles;
public PagerAdapter(FragmentManager fman, Context con)
{
super(fman);
fragments = new Fragment[3];
// Каждой страничке ViewPager соответствует свой фрагмент.
// Тут я создаю объекты и забиваю их в массив
fragments[0] = new SettingsFragment();
fragments[1] = new PassGenFragment();
fragments[2] = new HistoryFragment();
titles = new String[3];
titles[0] = con.getString(R.string.settings);
titles[1] = con.getString(R.string.main_fragment);
titles[2] = con.getString(R.string.history_fragment);
}
public Fragment getItem(int pos)
{
return fragments[pos];
}
public int getCount()
{
return fragments.length;
}
public CharSequence getPageTitle(int position)
{
return titles[position];
}
}
...
p_adapter = new PagerAdapter(getSupportFragmentManager(),
getApplicationContext());
pager = (ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(p_adapter);
pager.setCurrentItem(1);
...
public class PassGenFragment extends Fragment
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inf, ViewGroup cont, Bundle savedState)
{
View view = inf.inflate(R.layout.pass_gen_layout,null);
return view;
}
}