I developed one application in that I used a pager view using a snippet. In this, I go from one page to another using the class.in fragment in the second fragment class. I have one button on what I am writing the encoding to go directly to the first fragment through fragment.replace, but after replacing the first fragment I do not scroll the pager page one by one, because when I click the "Back" button, I go to the first fragment, but I cannot return to this class. So I have no idea to move the move / scroll page again to go to the second snippet. please help me quickly, thanks in advance.
My first follewing class:
enter code here
public class ViewPagerMainActivity extends FragmentActivity implements
OnClickListener, OnPageChangeListener {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
);
setTheme(android.R.style.Theme_Light_NoTitleBar);
setContentView(R.layout.view_pager_main);
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(
android.support.v4.app.FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public Fragment getItem(int pos) {
switch (pos) {
case 0:
return FirstFragment.newInstance("");
case 1:
return SecondFragment.newInstance("");
default:
return SecondFragment.newInstance("Default");
}
}
@Override
public int getCount() {
return 2;
}
}
@Override
public void onClick(View v) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int arg0) {
}
@Override
public void onBackPressed() {
}
}
enter code here SECOND FILE
public class FirstFragment extends Fragment implements OnTouchListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().setTheme(android.R.style.Theme_Light_NoTitleBar);
v = inflater.inflate(R.layout.sliding_lock_pager, container, false);
return v;
}
public static FirstFragment newInstance(String text) {
FirstFragment f = new FirstFragment();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
} third file enter the code here Public class SecondFragment extends Fragment implements OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().setTheme(android.R.style.Theme_Light_NoTitleBar);
View v = inflater.inflate(R.layout.password, container, false);
txtBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final android.support.v4.app.FragmentTransaction ft = getFragmentManager()
.beginTransaction();
ft.replace(R.id.layputMainPager, new FirstFragment(),
"NewFragmentTag");
ft.addToBackStack(null);
ft.commit();
}
});
return v;
}
public static SecondFragment newInstance(String text) {
SecondFragment f = new SecondFragment();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
@Override
public void onClick(View v) {
}
}
See in secondFragment class when i back through back button then i want to scroll again to that page i not do that. i move again to that page though page scroll. and in ft.replace(R.id.layputMainPager, new FirstFragment()) R.id.layputMainPager is `class ViewPagerMainActivity` class xml files a
main layout identifier.