fragmenttransaction

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

Fragment Transaction without commit

↘锁芯ラ 提交于 2019-12-11 07:22:58
问题 I have seen the code below and unable to figure it out. if (mGoalProgressFragment != null) { mCallerFramgent.getActivity().getSupportFragmentManager().beginTransaction().show(mGoalProgressFragment); } mCallerFramgent.getActivity().getSupportFragmentManager().beginTransaction().commit(); i am not able to understand the part when the if condition fails and commit() is called. and when if condition is true commit is not used for show transaction. Can anyone help me understand this. because lint

How do I dynamically make this child Fragment's TextView visible/invisible?

半城伤御伤魂 提交于 2019-12-11 02:04:59
问题 I have a main Activity containing a parent Fragment, which in turn contains a child Fragment. I am trying to make a TextView in the child Fragment visible/invisible dynamically. activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"

Multiple calls to FragmentTransaction.replace() - only one works after orientation change

試著忘記壹切 提交于 2019-12-11 02:04:39
问题 I am using the following code to populate my UI with 2 fragments, the containers are FrameLayout 's defined in XML. This first time this code is called i.e. when the app starts, it works fine, and both my fragments are displayed as expected. However after a configuration change(specifically, orientation), only the first fragment in the transaction is shown. I don't think it's an issue with the fragments themselves, because if I reverse the code so one replace is called before the other or

When is it safe to commit a FragmentTransaction?

白昼怎懂夜的黑 提交于 2019-12-10 14:49:12
问题 According to the docs A fragment transaction can only be created/committed prior to an activity saving its state. If you try to commit a transaction after Activity.onSaveInstanceState() (and prior to a following Activity.onStart or Activity.onResume(), you will get an error. I can understand that the first part that a fragment transaction can't committed after Activity.onSaveInstanceState(), because the state after the commit can be lost if the activity needs to be restored. But I don't

FragmentTransaction not doing anything

喜欢而已 提交于 2019-12-09 15:34:45
问题 I am learning fragments and below given is my first fragment program. A simple project where I have 2 screens. When I click the next button of first screen, second button needs to be shown. I am targeting Android 2.1 and above and using compatibility package AppMainFragmentActivity.java public class AppMainFragmentActivity extends FragmentActivity { @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.app_main_layout); } } app_main_layout.xml <?xml

How to add a fragment to a layout of a DialogFragment?

心已入冬 提交于 2019-12-07 07:01:34
问题 I am having a custom DialogFragment which contains a layout, some UI elements, and a Fragment holder layout. What I need to do is inflate a Content fragment into the holder layout and provide a navigation inside that. On clicking a button inside the added fragment the view will navigate to another view. The fragment will be replaced by another one in the same holder i.e. the contentFragment1 will show some data and on clicking a preview button there will replace contentFragment1 with

Android: Getting white screen with fragment transaction

半腔热情 提交于 2019-12-07 05:30:10
问题 I am making a news app where I have a fragment that holds all the news in a list and another fragment that have videos list. When you touch a new it will call a method from the activity named openNewsCont that will replace the current fragment with another one. The proble I am having is when I call that method I get a blank screen, I have looked many other codes but I couldn't find the solution for my problem. Here is the method I call from the MainActivity.java public void openNewsCont

Show a fragment with shared elements animation

独自空忆成欢 提交于 2019-12-05 22:41:21
In my app I have code like this: final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, fragment, "tag"); transaction.addSharedElement(view, "transitionName"); transaction.addToBackStack(null) .commit(); It works fine, shared elements animation works. But if I change this code like getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, fragment, "tag") .hide(fragment) .commit(); final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(oldFragment

Is it OK to addToBackStack and replace in a fragment transaction?

眉间皱痕 提交于 2019-12-05 13:32:26
问题 Any thoughts on the following code? In my testing I've found the replaced fragment isn't destroyed and the instance is still around when popping the back stack. Just looking to verify that this is a valid way to use fragment transactions. getSupportFragmentManager().beginTransaction().addToBackStack(null).replace(frame, fragmentB).commit(); My reason for using replace is that it causes the replaced fragment to run it's exit animation. 回答1: You can refer to the android designer guide for