ImageView Change after SwipeTabs Android - java

After I take my Photo and Signature, it displays on the ImageView. However, after I swap the tabs the ImageView returns to its default Image. See my screenshot.
There's no problem when it comes to editText the inputted value is still there. However, the ImageView is my problem. What's causing this problem? And how can I fix this?
Code:
public class RegisterUser extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.activity_register_user,container,false);
// Setting ViewPager for each Tabs
ViewPager viewPager = (ViewPager) v.findViewById(R.id.viewpager);
setupViewPager(viewPager);
// Set Tabs inside Toolbar
TabLayout tabs = (TabLayout) v.findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
// Create Navigation drawer and inlfate layout
return v;
}
// Add Fragments to Tabs
private void setupViewPager(ViewPager viewPager) {
Adapter adapter = new Adapter(getChildFragmentManager());
adapter.addFragment(new ListContentFragment(), "Info 1");
adapter.addFragment(new TileContentFragment(), "info 2");
adapter.addFragment(new CaptureSignatureActivity(), "info 3");
adapter.addFragment(new CardContentFragment(), "info 4");
viewPager.setAdapter(adapter);
}
static class Adapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public Adapter(FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
}

When you swipe through tabs (Fragments, actually) in a TabLayout, the default behaviour is that the system kills the previous Fragment to free memory and the subsequent Fragment to the current one will be loaded in the memory.
Now, with your code something similar is happening. When you load a photo and a signature in the 3rd tab (CaptureSignatureFragment) and then swipe through the tabs, the CaptureSignatureFragment is killed and thus both the ImageViews have the default images set to them.
If you wish to keep the data in the 3rd tab intact even after changing tabs, you should better set your ViewPager's offscreen limit to 4 (no. of tabs you have) by:
viewPager.setOffscreenPageLimit(4)
Now, changing the tabs won't kill any of the fragments. However, doing this can create performance issues.

Related

App kept stop running in Emulator in Android Studio

I've been following a tutorial on YouTube about tab layouts and when I was finish following it and run the application, the app kept stop running. So, I open my logcat to see what was wrong and it says: "Caused by java.lang.ClassCastException: androidx.viewpager.widget.ViewPager cannot be cast to com.google.android.material.tabs.TabLayout". I was unable to find what "cannot be cast to" means and can't find any documents explaining it.
private Toolbar toolbar;
private ViewPager viewPager;
private TabLayout tabLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbarClipBridge);
setContentView(R.layout.activity_main);
viewPager = findViewById(R.id.viewpagerClipBridge);
tabLayout = findViewById(R.id.viewpagerClipBridge);
fragmentDevices fragmentDevices = new fragmentDevices();
fragmentSyncActivity fragmentSyncActivity = new fragmentSyncActivity();
fragmentSettings fragmentSettings = new fragmentSettings();
ViewPageAdapter viewPageAdapter = new ViewPageAdapter(getSupportFragmentManager(), 0);
viewPageAdapter.addFragment(fragmentDevices, "Devices");
viewPageAdapter.addFragment(fragmentSyncActivity, "Sync Activity");
viewPageAdapter.addFragment(fragmentSettings, "Settings");
viewPager.setAdapter(viewPageAdapter);
tabLayout.getTabAt(0).setIcon(R.drawable.ic_baseline_devices_24);
tabLayout.getTabAt(1).setIcon(R.drawable.ic_baseline_sync_24);
tabLayout.getTabAt(2).setIcon(R.drawable.ic_baseline_settings_24);
}
private class ViewPageAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments = new ArrayList<>();
private List<String> fragmentTitle = new ArrayList<>();
public ViewPageAdapter(#NonNull FragmentManager fm, int behavior) {
super(fm, behavior);
}
public void addFragment(Fragment fragment, String title){
fragments.add(fragment);
fragmentTitle.add(title);
}
#NonNull
#Override
public Fragment getItem(int position) {
return fragments.get(position);
}
#Override
public int getCount() {
return fragments.size();
}
#Nullable
#Override
public CharSequence getPageTitle(int position) {
return fragmentTitle.get(position);
}
}
Logcat:
Caused by: java.lang.ClassCastException: androidx.viewpager.widget.ViewPager cannot be cast to com.google.android.material.tabs.TabLayout
Image of my logcat
In the line:
viewPager = findViewById(R.id.viewpagerClipBridge);
tabLayout = findViewById(R.id.viewpagerClipBridge);
The code tries to look into your activity_main.xml file and find an XML object with the id R.id.viewpagerClipBridge. The XML object is probably of the type ViewPager.
In the following line, the code looks again into the XML file. Again, with the id R.id.viewpagerClipBridge, the code tries to set the return value to a variable tab layout of type TabLayout.
And since the type of ViewPager != type of TabLayout it cannot be cast to that type.
I think you used the wrong id in the second findViewById line. Investigate your activity_main.xml and look for the id of your TabLayout.

ViewPager2 not working properly with Fragments and click events

I just wanna know if I'm doing something wrong since I'm kinda new to all this.
If there is anything else that you'll like me to add just let me know.
This is the repo branch where I'm trying to implement the ViewPager if you wanna see all the code.
Context
So I have 4 Categories represented with Fragments, each of this categories holds an ArrayList of items that each has a onItemClickListener that should reproduce some audio.
I'm trying to display the Fragments with a ViewPager but the problem is that when I scroll from a Fragment to another, then come back to the already created Fragment, it doesnt register the touch event, nothing happens, not even an error nor exception.
If I go to a newly created Fragment the touch works just fine.
Also, after switching back to an already created Fragment if I scroll even just a little bit to another Fragment and comeback or through the ArrayList of that Fragment for some reason it starts to recognize the touch in the ArrayList items again.
Similar questions that didn't really help
Fragments in ViewPager2 does not respond to clicks if scroll position is 0
ViewPager2 conflicting with SwipeRefreshLayout
Android ViewPager2 with fragment containing a recyclerview not scrolling
What I've tried
I tried to use a coordinatorlayout wrapping the ViewPager2 but there is no difference
I've been reading some of the official viewPager2 examples that are written in Kotlin but none of them seem to have a similar situation (also it's hard for me to read Kotlin code)
Code Snippets
word_list.xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/tan_background" />
activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"/>
</FrameLayout>
This is one of the Fragments, the other three are basically the same, just the items in the arrayList change and some other minor things:
// ...Skipped some irrelevant code...
public class NumbersFragment extends Fragment {
private ArrayList<Word> mWords;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.word_list, container, false);
mWords = new ArrayList<>();
// ...Add all the items to the list...
// Make the adapter for the word items
WordAdapter adapter = new WordAdapter(getActivity(), mWords, R.color.category_numbers);
// Find the root view of the list
ListView listView = rootView.findViewById(R.id.root_list_view);
// Add adapter to the root list view
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("NumbersFragment", "CLICKED");
}
}
});
return rootView;
}
#Override
public void onPause() {
super.onPause();
Log.d("NumbersFragment", "Fragment paused");
}
}
This is the Category adapter, it manages the fragments:
public class CategoryAdapter extends FragmentStateAdapter {
private static final int NUM_CATEGORIES = 4;
// Required public constructor
public CategoryAdapter(#NonNull FragmentActivity fragmentActivity) {
super(fragmentActivity);
}
#NonNull
#Override
public Fragment createFragment(int position) {
// Depending on which page the user is in,
// create a fragment of the corresponding category
switch (position) {
case 0:
return new NumbersFragment();
case 1:
return new FamilyFragment();
case 2:
return new ColorsFragment();
default:
return new PhrasesFragment();
}
}
#Override
public int getItemCount() {
return NUM_CATEGORIES;
}
}
And this is my MainActivity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
// Find the view pager that will allow the user to swipe between fragments
ViewPager2 viewPager = findViewById(R.id.viewpager);
// Create an adapter that knows which fragment should be shown on each page
CategoryAdapter adapter = new CategoryAdapter(this);
//or CategoryAdapter adapter = new CategoryAdapter(getSupportFragmentManager(), getLifecycle());
// Set the adapter into the view pager
viewPager.setAdapter(adapter);
}
}
add this in your MainActivity viewPager.setOffscreenPageLimit(3); after creating viewpager
It’s because the ViewPager has a default offscreen limit of 1 ,and ViewPager2 has a default offscreen limit of 0.
In ViewPager2 when you switch tabs the previous tab will be automatically refreshed.
in ViewPager if you have 3 tabs or more when you switch to 3rd tab automatically first one will be destroyed and when you goes to 1st tab it will be recreated.
viewPager.setOffscreenPageLimit(3); from this line when you switch to a tab,the previous 3 tabs will be preloaded and next 3 tabs will be preloaded so nothing will be refreshed.

How to refresh TabbedActivity's View from onRestart method | How to access fragment's view element from other class

I've created activity from TabbedActivity template (in Android Studio):
This template uses Fragment and FragmentPagerAdapter to handle tabs.
This is code of two classes, PlaceholderFragment extends Fragment, and SectionsPagerAdapter extends FragmentPagerAdapter:
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_list_view, container, false);
int scnum = getArguments().getInt(ARG_SECTION_NUMBER);
final ListView listView = (ListView) rootView.findViewById(R.id.products_list);
// here refresh my listView trough internet
return rootView;
}
}
/**
* A {#link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(position + 1);
}
#Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}
In onCreateView method I refresh my ListView. This method is called when i switch tabs.
But I need to refresh ListView not when user switch tabs, but:
1. every 10 seconds
2. when user comes back to this activity (onRestart() method is called)
I have no idea how to access my ListView outside onCreateView method.
I've already tried many solutions from the internet to call onCreateView method from onRestart method, and just to access my ListView from onRestart(). None of them worked.
Globally in Activity class I have an instance of SectionsPagerAdapter and ViewPager:
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
They are initalized in onCreate by this way:
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
I think, there are 2 possible solutions, access my Fragment's view or just recall onCreateView.
I've already tried to do:
This one just doesn't work:
#Override
protected void onRestart() {
super.onRestart();
mSectionsPagerAdapter.notifyDataSetChanged();
}
This one crashes app because of NullPointerException:
#Override
protected void onRestart() {
super.onRestart();
Fragment f = mSectionsPagerAdapter.getItem(0); // tab with my list view is first tab. ( getItem(1) also does not work )
View v = f.getView(); // v is null here, however f isn't.
final ListView listView = v.findViewById(R.id.products_list); // v is null, NullPointerException is thrown.
// here refresh my listView trough internet
}
EDIT:
Since I started using Kotlin, answer based on that language will be also accepted. However, I am new to Kotlin, so more detailed answer would be needed then.
So you have a list in a Fragment that is inside a ViewPager. Ther are a few ways to solve your problem, I'd suggest you use the first one, because it is the simplest.
Fragment have lifecycle callbacks that are triggered together with lifecycle callbacks of Activity that contains that fragment. It covers most of the methods, but unfortunately not the onRestart that you are looking for. But that's not a big problem. Actually, you almost never need onRestart because you have onStart method, that method is accessible from both Fragments and Activities. It is called every time activity is restarted + the very first time activity is started. And as we can see it is exactly what you need. So to have your list updated every time, just remove the update code from the onCreate method and put it into onStart method of the Fragment.
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
private ListView listView = null;
public PlaceholderFragment() {
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_list_view, container, false);
int scnum = getArguments().getInt(ARG_SECTION_NUMBER);
listView = (ListView) rootView.findViewById(R.id.products_list);
return rootView;
}
#Override
public void onStart() {
// here refresh your listView trough internet using the listView class field
}
}
Another option would be to get a reference to your fragment inside the activity. The solution I usually use is to retain a reference to the fragment inside the adapter. It is similar to the second option in your question. The only problem with your solution is that mSectionsPagerAdapter.getItem(0); always create a new fragment, while you need to get a reference to already existing fragment.
public class SectionsPagerAdapter extends FragmentPagerAdapter {
private PlaceholderFragment fragmentZero = null;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
PlaceholderFragment tabFragment = PlaceholderFragment.newInstance(position + 1);
if (position == 0) {
fragmentZero = tabFragment;
}
return tabFragment;
}
#Override
public int getCount() {
return 3;
}
public PlaceholderFragment getFragmentZero() {
return fragmentZero;
}
}
You also need to move your list update logic to a separate method in the PlaceholderFragment:
private ListView listView = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_list_view, container, false);
int scnum = getArguments().getInt(ARG_SECTION_NUMBER);
listView = (ListView) rootView.findViewById(R.id.products_list);
refreshListView();
return rootView;
}
public void refreshListView() {
// here refresh your listView trough internet
}
At this point you can do:
#Override
protected void onRestart() {
super.onRestart();
Fragment listFragment = mSectionsPagerAdapter.getFragmentZero();
listFragment.refreshListView();
}
Whenever you have a fragment inside an activity, in a ViewPager or not, you can get a reference to the fragment using FragmentManager. Check this for details regarding the ViewPager option.
All the code above is rather straightforward and would not require any special Kotlin idioms if you'd prefer to implement it in Kotlin. You can start with converting your classes in the android studio. To do it:
Navigate to your java class
Press Control + Shift + A on Windows or Command + Shift + A on Mac
Search for Convert Java File to Kotlin File
Apply
And you are good to go with the Kotlin code of given classes. The only thing that might be quite different from java is handling ARG_SECTION_NUMBER since Kotlin does not have static fields and use Companion Objects instead.

Access method from Dialog to MainActivity

I have a main Activity in which I created a ViewPager that instantiate 3 other Fragments. One of these is a GridView which makes a popup appear when the user click on one item. Then, in this popup, I have a simple button.
What I want to do is: when the user click on this button, I would like to access a method in my main Activity (that should change the current item of my ViewPager) and then dismiss the popup.
I tried everything I could, but I cannot achieve this... I can set up the click event on my popup and dismiss it easily, but I didn't find out how I can access a method (or even a variable) from my popup to my main Activity.
I will put my most relevant code in here so you can understand the structure of my classes (hopefully...).
My main Activity:
public class MainActivity extends FirstActivity{
private ViewPager mViewPager;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
// Set an Adapter on the ViewPager
mViewPager.setAdapter(new MainActivity_Adapter(getSupportFragmentManager()));
public void onSaveInstanceState(Bundle savedInstanceState)
{
menuBar.onSaveInstanceState(savedInstanceState);
}}
My ViewPager activity:
public class MainActivity_Adapter extends FragmentPagerAdapter{
public MainActivity_Adapter(FragmentManager fm)
{
super(fm);
}
#Override
public Fragment getItem(int position)
{
// Set the color background for each page
switch (position)
{
case 0:
return MainActivity_Inventory.newInstance();
case 1:
return MainActivity_Map.newInstance();
default:
return MainActivity_AR.newInstance();
}
}
// The number of Splash Screens to display
#Override
public int getCount()
{
return 3;
}}
My "Inventory" Fragment
public class MainActivity_Inventory extends Fragment implements View.OnClickListener{
public static MainActivity_Inventory newInstance()
{
MainActivity_Inventory frag = new MainActivity_Inventory();
Bundle b = new Bundle();
frag.setArguments(b);
return frag;
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Select the layout
int layout;
layout = R.layout.activity_inventory_01;
// Inflate the layout resource file
View view = getActivity().getLayoutInflater().inflate(layout, container, false);
// Set the grid view
GridView gridview = (GridView) view.findViewById(R.id.inventory_gridView);
gridview.setAdapter(new InventoryImageAdapter(super.getActivity()));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position, long id)
{
// Create a popup to show item details
createPopup();
}
});
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
}
public void createPopup()
{
DialogFragment newFragment = new PopupActivity_Inventory();
newFragment.show(getFragmentManager(), "itemDetails");
}
#Override
public void onClick(View v)
{
}}
And my popup dialog fragment:
public class PopupActivity_Inventory extends DialogFragment{
#Override
public Dialog onCreateDialog(final Bundle savedInstanceState)
{
// Build the alert dialog
final Dialog dialog = new Dialog(this.getActivity());
// Get the layout inflater
final LayoutInflater inflater = getActivity().getLayoutInflater();
// Set up the dialog box
dialog.setContentView(inflater.inflate(R.layout.activity_inventory_popup_01, null));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setGravity(Gravity.TOP);
//dialog.getWindow().getAttributes().y = 100;
(dialog.findViewById(R.id.brick_button_01)).setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
// When button is clicked, ACCESS MAIN ACTIVITY!
dialog.dismiss();
}
});
return dialog;
}}
I really hope you can help me with this... I really need to get it working. Thank you very much!
If you need further details or explanation, please just tell me.
The best thing to do is use EventBus library. I have a demo app in which you can add items to RecyclerView from anywhere within the app using EventBus. You can use it as a reference to simply do something else instead of current task. Here is the link to the repo:
https://github.com/code-crusher/android-demos/tree/master/EventBusDemo
And if you want to understand how it works you can refer to my article, it explains how to make communications like this easy:
https://medium.com/#code_crusher/eventbus-for-android
Hope it helps. Happy coding :)
Read this https://developer.android.com/training/basics/fragments/communicating.html
Look for "To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity...."
Another way to achieve it is using an EventBus and post events by Fragments to be caught by Activities.

Android ViewPager Bug on Swipe

I have this weird issue with the viewPager. When I swipe from one fragment to the next and then swipe back, the layout is correct, but when pressing an element (Listview item for example), the previous java code still did not update with the view. I don't know if I can explain this any better, as it works when I play with the swipe until the fragment works like its supposed to. here is my code:
Main.Java:
public class Main extends FragmentActivity {
SectionsPagerAdapter mAdapter;
ViewPager mViewPager;
// for alert transitions
AlertDialog dialog;
// share button
private ShareActionProvider mShareActionProvider;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// set up button
getActionBar().setDisplayHomeAsUpEnabled(true);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mAdapter);
mViewPager.setPageTransformer(true, new DepthPageTransformer());
}
#Override
public void onBackPressed() {
if (mViewPager.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.
mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
}
}
}
SectionsPagerAdapter.java:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new Important();
case 1:
return new Propositions();
case 2:
return new Information();
}
return null;
}
#Override
public int getCount() {
// Show 3 total pages.
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return ("Important Dates").toUpperCase(l);
case 1:
return ("Props").toUpperCase(l);
case 2:
return ("Information").toUpperCase(l);
}
return null;
}
}
The Fragments all use the onCreateView() method.
Thanks in advance for your help!
Maybe a late response, but I've experienced the same issue.
The problem was the DepthPageTransformer you are using from the Android Developers example for PageTransformer.
There is a bug with stacking fragments and layer priority, I assume. By fixing the custom PageTransformer will fix your "swipe back" issue. Or if you don't mind the animation, just remove your custom PageTransformer and use the default animation (by adding nothing).

Categories