This problem only ocurs in lollipop. kitkat and previous versions work correctly!
The problem is that I have implemented a slider using a pageview, in the first fragment I have the login fragment with two buttons.
When the app start there isn't a problem, but when I change the fragment using page view and back to the login fragment, the buttons not working.
The buttons load the register form or login form in the same fragment. There isn't an error, only the button does nothing.
This is the code:
public class ScreenSlideActivity extends ActionBarActivity {
/**
* The number of pages (wizard steps) to show in this demo.
*/
private static final int NUM_PAGES = 5;
/**
* The pager widget, which handles animation and allows swiping horizontally to access previous
* and next wizard steps.
*/
private ViewPager mPager;
/**
* The pager adapter, which provides the pages to the view pager widget.
*/
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_slide);
// Instantiate a ViewPager and a PagerAdapter.
/*postponeEnterTransition();
mPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
mPager.getViewTreeObserver().removeOnPreDrawListener(this);
startPostponedEnterTransition();
return true;
}
});*/
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setPageTransformer(true, new DepthPageTransformer());
LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(mPager);
}
@Override
public void onBackPressed() {
if (mPager.getCurrentItem() == 0) {
// If the user is currently looking at the first step, allow the system to handle the
// Back button. This calls finish() on this activity and pops the back stack.
super.onBackPressed();
} else {
// Otherwise, select the previous step.
mPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
}
/**
* A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in
* sequence.
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch(position)
{
case 0:
return new LoginSignupFragment();
default:
return new SlidePageFragment();
}
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}
The first fragment's code to load the login form or register form is:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.fragment_slide_login, container, false);
ingresarBtn = (Button) rootView.findViewById(R.id.ingresarBtn);
ingresarBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment frag = new LoginFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.slide_login_content, frag);
transaction.addToBackStack(null);
transaction.commit();
}
});
unirseBtn = (Button) rootView.findViewById(R.id.unirseBtn);
unirseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment frag = new SignupFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.slide_login_content, frag);
transaction.addToBackStack(null);
transaction.commit();
}
});
return rootView;
}
If is necessary more information, I will give.