I want to passes some value inside button click with viewpager tab fragment changing. I have two question.
If I use static data what will be problem? such like:
public static string abc=""
case R.id.IVActionMore:
ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.tabs_viewpager);
viewPager.setCurrentItem(3);
//abc = "action";
break;
You can use shared-preference to set and get the data. using static is not a great idea. check the link
https://stackoverflow.com/a/23024962/4549220
void addOnPageChangeListener (ViewPager.OnPageChangeListener listener) Add a listener that will be invoked whenever the page changes or is incrementally scrolled.
How ?
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float
positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position)
{
if(position == 3)
{
// DO your work
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
OnClick
buttonOBJ.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, true);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With