I've a ViewPager that uses a FragmentPagerAdapter, with 3 pages on it, and what I want is to inflate a new fragment layout on the top of my middle fragment when a button is pressed.
This was what I tried:
MainActivity.java
...
// Method that is called when the button is cliked
public void buttonCliked(View view) {
viewPager.setCurrentItem(5);
}
...
MyAdapter.java
public Fragment getItem(int i) {
Fragment fragment = null;
if(i == 0) {
...
}
else if(i == 1) {
..
}
else if(i == 2) {
..
}
else if(i == 5){
fragment = MyFragment.newInstance("aa", "aa");
}
return fragment;
}
But basically what's happening is, when I pressed the button, the ViewPager slides to the new fragment instead of replacing it. Any ideas how can I make this work the way I want?
Summing up how can I inflate a new layout on the top of the select fragment in a ViewPager?
Thanks.