fragmentmanager

Attempt to refresh fragment gives me NullPointerException; I've made sure compatibility isn't an issue, and my fragments shouldn't be null

隐身守侯 提交于 2019-12-11 16:14:44
问题 I am currently trying to implement code in my android project where my fragments will refresh after a button is pressed, recreating the view and displaying different items. I made sure there were no compatibility issues between android.app and android.support.v4.app, and am positive that I have my fragments' id's labelled correctly. Here is the exact error I received when running my app on an emulator: java.lang.NullPointerException: Attempt to write to field 'int android.support.v4.app

FragmentPagerAdapter throwing IllegalArgumentException - Fragment Already Added

孤人 提交于 2019-12-11 14:55:07
问题 I have a ViewPager and a TabLayout containing 3 Fragments. At times when I swipe through(with the help of ViewPager ) the 3 Fragments, an IllegalArgumentException is thrown with a message that Fragment is already added: ... (Fragment at index 0 to be specific). What could be the problem as the error log is only showing something to do with FragmentManager class and none of my Fragment classes? Below is the adapter(s) I am using import androidx.fragment.app.Fragment import androidx.fragment

Show SimpleDialogFragment message alert in a fragment

冷暖自知 提交于 2019-12-11 14:54:05
问题 I have a Main activity that extends from FragmentActivity, like this: public class Main extends FragmentActivity{ public static FragmentManager fragmentManager; public static CustomFragmentAdapter mAdapter; ... //I can access to canAccessFromMain() in SecondTab like this: ((SecondTab)Main.mAdapter.getRegisteredFragment(1)).canAccessFromMain(); } With two fragments, like this: public class SecondTab extends Fragment implements ISimpleDialogListener{ ... //Access to objects in Main like this:

Replacing fragments quickly causes a weird screenshot of the previous fragment to persist and brought forward

吃可爱长大的小学妹 提交于 2019-12-11 13:06:28
问题 I'm using a HomeActivity which replaces fragments dynamically and adds it to content frame layout dynamically as the user selected items from the drawer. On each fragment, it loads a feed from the network which it then renders. Here is the code I use for the switch - public void loadFragment(Fragment frag, String tag) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id

Why I am getting “Cannot remove Fragment attached to a different FragmentManager” in Android?

北城余情 提交于 2019-12-11 12:03:17
问题 I am trying to remove a fragment but very rarely on Crashlytics I am able to see a bug java.lang.IllegalStateException: Cannot remove Fragment attached to a different FragmentManager. I have a separate fragment for fetching user's current location. I use below code to open the fragment. private void openLocationFragment() { LocationFragment locationFragment = LocationFragment.newInstance(); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction()

DialogFragment behaves differently when invoked via ActionBar

烈酒焚心 提交于 2019-12-11 10:27:37
问题 I'm experiencing strange, perhaps version-specific behavior with my DialogFragment subclass when testing the following steps: (1) Open the dialog (2) Leave the app with either the Home key or the Recent Apps key (3) Return to the app, and the dialog is no longer visible. It seems to be briefly, translucently visible behind the main activity. (4) Rotate the device, and the dialog re-appears. This bug occurs on my Asus TF700T pad running Android 4.2.1, and it does not occur on my Motorola Razr

Android Fragments - Multiple tabs/pageflows, custom backstack

痴心易碎 提交于 2019-12-11 07:51:49
问题 I'm running into memory issues with fragments and I could use some help as to the appropriate path to take. I cannot use a simple backstack because the application needs to retain several paths that the user takes within the application (and the user can jump back and forth). The navigation handles fragments in this way: transaction.hide(currentFragment).show(newFragment).commit(); What I think would help my situation is having the view of the fragment temporarily destroyed and then recreated

FragmentStatePagerAdapter - getItem

我与影子孤独终老i 提交于 2019-12-11 06:16:46
问题 I know there are several other posts on this topic, but I wanted to paste my code because I believe there may be an error in it that is causing my problem. My FragmentStatePagerAdapter is returning the wrong position, and I am not sure why. Here is the code in my Main activity. Main.java import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app

Add fragment into react-native view

和自甴很熟 提交于 2019-12-11 04:29:33
问题 Long story short: I'm trying to create a native module for an react-native project for AndroidPay. Integration of AndroidPay is possible only using fragments (which are in final "Buy with AndroidPay" buttons). So the algorithm is pretty simple, export a placeholder in react-native, wrap it in a component and at some point just add fragment into that placeholder using it's id. So the code looks like: public class AndroidPayPlaceholderViewManager extends SimpleViewManager<FrameLayout>{ public

How to remove fragment from fragment manager when activity is restored after being destroyed

寵の児 提交于 2019-12-11 03:44:20
问题 I have an activity A which contains fragment F. A shows F by pushing it onto fragment manager's back stack. This fragment may show a dialog(more specifically, a DialogFragment) D, also by pushing it to the same fragment manager's back stack. I need to be able to dismiss dialog D under certain circumstances that are determined by fragment F. Normally I would check if D is on the fragment manager's back stack and use getFragmentManager().popBackStack() to remove it. But this doesn't work if the