0
It is possible to add a fragment with TABS (HORIZONTAL VIEW SWIPING WITH TABS) inside another fragmneto?
0
It is possible to add a fragment with TABS (HORIZONTAL VIEW SWIPING WITH TABS) inside another fragmneto?
0
I solved the problem with this adaptation:
public class FragListaJogos extends Fragment{
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
private View view;
private FragmentActivity myContext;
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
view= inflater.inflate(R.layout.layout_lista_jogos, container, false);
mSectionsPagerAdapter = new SectionsPagerAdapter(myContext.getSupportFragmentManager());
mViewPager = (ViewPager) view.findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
return view;
}
@Override
public void onAttach(Activity activity) {
myContext=(FragmentActivity) activity;
super.onAttach(activity);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return ("Teste1").toUpperCase(l);
case 1:
return ("Teste2").toUpperCase(l);
case 2:
return ("Teste3").toUpperCase(l);
}
return null;
}
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.layout_lista_jogos, container, false);
return rootView;
}
}
}
Basically I gave an Override in the onAttach method this way:
public void onAttach(Activity activity) {
myContext=(FragmentActivity) activity;
super.onAttach(activity);
}
Browser other questions tagged android android-fragment
You are not signed in. Login or sign up in order to post.