fragmentmanager

Backstack management : Restarter must be created only during owner's initialization stage

北慕城南 提交于 2019-12-28 21:41:52
问题 I am using a bottom navigation bar in my MainActivity to handle some fragments. This is the code used for switching between them: private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> if (item.isChecked && supportFragmentManager.findFragmentById(R.id.act_main_fragment_container) != null ) return@OnNavigationItemSelectedListener false val fragment = when (item.itemId) { R.id.navigation_home -> fragments[0] R.id.navigation_bookings ->

Supporting different screen sizes with dynamic or static fragments?

て烟熏妆下的殇ゞ 提交于 2019-12-25 16:54:35
问题 I am found it confusing to be able to support multi screens using fragments. I thought the idea was that i could offer more than one version of the activity and that activity could have 1 or more fragments (depending on real estate) statically embedded. Supporting dynamic fragments where these are added from code rather than embedded <fragment> element types. How would this be done in code as I wouldn't know the configuration details of the xml from the activity. Does anyone have an example

Get fragment from backstack for second time

冷暖自知 提交于 2019-12-25 08:28:02
问题 i'm currently working on browser app for an android. I'm managing new tabs with fragments. So everything is working fine when user open new tab B, and then go back again to tab A. The problem appear when from A he try to go back again to B. With other words its not working when you tries to pop back same fragment for the second time. This is how I'm adding new tabs- fragments android.app.Fragment f1 = new FragmentHolder(); allFragments.add(f1); getFragmentManager().beginTransaction().replace

How to get previous fragments?

时光怂恿深爱的人放手 提交于 2019-12-23 10:21:01
问题 In order to reuse some fragments in my app, I need to know which Fragment is the second on the back stack. In order to do that I'm using getFragmentManager().getFragments() , which shows the following error (but works!) FragmentManager.getFragments can only be called from within the same library group (groupId=com.android.support) Is it safe to use? Could I get the same result by another approach? Here is the code: public Fragment getCallerFragment(){ List<Fragment> fragments =

Check if a fragment exists and reuse it

*爱你&永不变心* 提交于 2019-12-23 09:26:43
问题 I'm using the following code to create a fragment everytime the user click on an item in a list view. But in this way the fragment is created at every user click. What I want is to reuse the old fragment (if it exists) and only reload its content (don't create a new one). MagazineViewFragment fragment = new MagazineViewFragment(); fragment.openStream(itemSelected); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.container, fragment)

How to avoid adding same fragment to stack

老子叫甜甜 提交于 2019-12-23 08:45:08
问题 I need some help. em adding fragment to activity this way. problem is on each call of openFragment it create fragment and add. which is obvious. Question: what modification i do, so it can add fragment only once. on the next call with same fragment tag it will do nothing. case: press button first time it add fragment and shows. i press again same button it response nothing. public static void openFragment(Activity activity, Fragment fragment) { FragmentManager fragmentManager = (

How to avoid adding same fragment to stack

主宰稳场 提交于 2019-12-23 08:44:24
问题 I need some help. em adding fragment to activity this way. problem is on each call of openFragment it create fragment and add. which is obvious. Question: what modification i do, so it can add fragment only once. on the next call with same fragment tag it will do nothing. case: press button first time it add fragment and shows. i press again same button it response nothing. public static void openFragment(Activity activity, Fragment fragment) { FragmentManager fragmentManager = (

Reload or notify Fragment's data in ViewPager

China☆狼群 提交于 2019-12-22 10:00:11
问题 I have [main]Fragment with two ViewPagers in it. Each ViewPager contains several Fragments in it. ViewPager 's Fragments obtain data into their ListViews from [main]Fragment . I need to update data in all ListViews , which comes from [main]Fragment . I've tried to remove current [main]Fragment and add new one (reload it), but when I am calling .remove([main]Fragment) or .detach([main]Fragment) methods in .supportFragmentManager() [main]Fragment is not destroying or detaching, it just hiding

fragment popbackstack behaviour broken in 25.1.0 and 25.1.1

耗尽温柔 提交于 2019-12-21 21:26:25
问题 Since support version 25.1.0 and the most recent 25.1.1 I got strange behaviour with fragment replacing/adding. There have been issues reported for 25.1.0 Android - fragmentTransaction.replace() not works on support library 25.1.0 But now in 25.1.1 i got similar issues. To reproduce the behaviour i created sample app which you can find at https://github.com/holoduke/fragmenttest It is basically one Activity with a fragment container. A couple of fragments are available which will be

java.lang.IllegalStateException(Can not perform this action after onSaveInstanceState)

大城市里の小女人 提交于 2019-12-21 20:43:10
问题 I am getting this error with following message in different scenario: Activity has been destroyed and Can not perform this action after onSaveInstanceState I am writing an app where Two Activity interacting with each Other. Activity-A launch Activity-B using Intent. This Activity-B class have two fragment children. Fragment-A use public method of activity to launch another Fragment-B . public void beginTransaction(ID id, Bundle bundle) { Fragment fragment = getFragmentItem(id); // In case