fragmenttransaction

How to add/remove Fragment on Button click?

眉间皱痕 提交于 2019-12-03 13:35:18
At present I have got a "RELATIVE_LAYOUT" container which I am using for adding my fragment. I am using OnClickListener on a button to load the fragment XML layout into the RelativeLayout container. What I want to achieve is that when I press the button once, the fragment should load...and when I press it again the fragment should be removed. I've already tried using integer to identify if fragment is loaded, but failed. Any help Appreciated... CODE: public class MainActivity extends Activity { Button B1,B2; int boolb1=0, boolb2=0; @Override protected void onCreate(Bundle savedInstanceState) {

android.R.id.content as container for Fragment

孤街醉人 提交于 2019-12-03 12:29:53
问题 My situation is Activity A which contains Fragment B. I always implement it like this. Layout for Activity A: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> Layout for Fragment B: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

Android FragmentTransaction.addToBackStack confusion

▼魔方 西西 提交于 2019-12-03 10:17:53
I was studying Fragments and got little confused on differentiating FragmentTransaction.replace(id, fragment, tag) and FragmentTransaction.addToBackStack(tag) calls. Lets say that my current fragment is FragmentA and then I loaded FragmentB . I want that in future, when I need to load FragmentA , I don't have to reload it. Just load the old one in old state. I used the following code segment: public void loadFragment(Fragment fragmentB, String tag) { FragmentManager fm = getSupportFragmentManager(); View fragmentContainer = findViewById(R.id.fragment_container); FragmentTransaction ft = fm

How to replace fragment C with fragment A when back button is pressed?

大兔子大兔子 提交于 2019-12-03 01:56:50
问题 My scenario : Activity 1 consists of Fragments A-> B-> C. All the fragments are added using this code : FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.content, fragment, TAG); ft.addToBackStack(TAG); ft.commit(); Now, from fragment C, I want to directly return to Fragment A. Therefore, I've commented ft.addToBackStack(TAG) while adding Fragment C. So when I press back button from C I directly get Fragment A on the screen.

Android Studio 0.2.2 + ActionBarSherlock settings: Could not find class 'android.support.v4.app.FragmentActivity'

放肆的年华 提交于 2019-12-02 15:48:41
问题 similar problem mention here. I set android-support-v4 to compiler also but still I am getting problem related to reference library. How can solve this issue? 回答1: As you requested my settings to be shared, I here post my project settings window. Hope that you can help. 1. ActionBarSherlock project. Note that only android-support-v4 is checked to be exported. 2. My personal project settings windows. Nothing special but only ActionBarSherlock project is referenced. 来源: https://stackoverflow

Android fragments overlap

五迷三道 提交于 2019-12-02 08:30:22
I have an activity with two fragments, one to display a list and one to show the details of the clicked item. When starting the app the detail part is something static, once I click an item it should get replaced. The problem is that the old fragment is not being replaced, so both views are on top of each other. My activity layout is: <?xml version="1.0" encoding="utf-8"?> <fragment android:id="@+id/listFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" class="com.fragments.FragmentOrderList" > </fragment> <fragment android:id="@+id

Fragment's Transaction replace on API-21 is staying behind

不想你离开。 提交于 2019-12-01 18:08:37
I am developing an app that uses fragments, last week my test device took lolipop update. When I test my app on a lolipop device, I saw that Fragment Transaction's replace method didn't work properly. It work with confusingly in Lolipop version although everything fine on Kitkat version. In order to explain my situation, I've added some images. --First Screen----------------------------KitKat-------------------------------------Lollipop------------- As you can see, when i use kitkat , everything fine but as soon as i use lolipop fragment transaction replace is working confusingly. Here is my

How do you handle fragment transactions when the state of the parent activity is bound to be saved?

最后都变了- 提交于 2019-12-01 16:04:56
My app has several fragments and activities. Over the course of the main parent activity's lifecycle, the app presents information/options to the user in other activities. The documentation for Fragments has the following stipulation for commit(): Caution: You can commit a transaction using commit() only prior to the activity saving its state (when the user leaves the activity). If you attempt to commit after that point, an exception will be thrown. This is because the state after the commit can be lost if the activity needs to be restored. For situations in which its okay that you lose the

How do you handle fragment transactions when the state of the parent activity is bound to be saved?

梦想的初衷 提交于 2019-12-01 15:26:28
问题 My app has several fragments and activities. Over the course of the main parent activity's lifecycle, the app presents information/options to the user in other activities. The documentation for Fragments has the following stipulation for commit(): Caution: You can commit a transaction using commit() only prior to the activity saving its state (when the user leaves the activity). If you attempt to commit after that point, an exception will be thrown. This is because the state after the commit

An invisible layout behind the fragment is getting clicked:

我是研究僧i 提交于 2019-11-30 17:15:53
I have created several fragments and I add the first fragment the following way: mainFragment = (MainFragment) MainFragment.create(); getSupportFragmentManager().beginTransaction() .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right) .add(R.id.content, mainFragment, MAIN_FRAGMENT_TAG) .commit(); The second fragment is added this way: getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right) //.hide(mainFragment) .add(R.id.content