Closed AlexandruDev closed 9 years ago
Hi, @MasterzYuri
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
getFragmentManager(), FragmentPagerItems.with(getActivity())
.add("First tab", Frag1.class)
.add("Second tab", Frag2.class)
.create()) {
@Override
public Fragment getItem(int position) {
return getPagerItem(position % 5).instantiate(context, position);
}
};
If you want to get a position in the Fragment side, you can get in this code.
class Frag1 {
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int position = FragmentPagerItem.getPosition(getArguments());
...
}
}
Solved?
Kind of... I'm having another issue and I have no ideea what's causing it. I recorded it so you can understand better what's happening: https://vid.me/NZQ4
So, my app is based on Navigation Drawer, it consists of a few fragments, one of the fragments has a ViewPager ( as you can see in the video ) with 3 tabs. The first time I click on that fragments it works perfectly, but if I press on it again the background will change to grey, it also affects the scrolling.
public class MainPlusViewPager extends Fragment {
public static MainPlusViewPager newInstance() {
return new MainPlusViewPager();
}
public MainPlusViewPager() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.main_plus_viewpager,
container, false);
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
getFragmentManager(), FragmentPagerItems.with(getActivity())
.add("RED", F1.class)
.add("BLUE", F2.class)
.add("GREEN", F3.class)
.create());
ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager_plus);
viewPager.setAdapter(adapter);
SmartTabLayout viewPagerTab = (SmartTabLayout) view.findViewById(R.id.viewpagertab_plus);
viewPagerTab.setViewPager(viewPager);
return view;
}
}
Issue solved, changed extends Fragment
to extends AppCompatActivity
Thanks again for this library!
:+1:
How can I adapt the above code so it will work with your library?
Thanks a lot for this library!