fragmenttransaction

FragmentTransaction : replace and addToBackStack not working together?

不想你离开。 提交于 2019-12-18 10:57:24
问题 I'm fairly new to Android development and now running in to weird behaviour. I have an empty FrameLayout to be the container of a fragment. If user press a button for the first time, generate new Fragment and put inside container. If user press a button later and there is existing fragment inside container, replace existing one with newly generated one. If user press back button, pop away the fragment inside container. Here is my code public void showFragment(View v) { FragmentA f = new

How can I implement FragmentManager and FragmentTransaction to replace just a single fragment?

二次信任 提交于 2019-12-18 06:18:05
问题 I have an activity with 3 fragments; a header; a body; a footer (same point as in HTML). The bodyfragment contains three buttons which each should replace the middle fragment (body; itself) with another one, but I can't figure out how to work FragmentManager and FragmentTransition in here. I can't seem to find any coherency in other peoples questions on here with regards to the way others implement their fragments. It seems everyone has their own methods, or just doesn't include the full code

How to replace Fragments of different types?

[亡魂溺海] 提交于 2019-12-13 19:17:13
问题 Good morning. I'm developing an app in which I have a main layout that extends from activity and inside this one I have one fragment of one data type, in my case FragmentCover (it's a class). During my app, I push a button and I want to change this fragment layout for another layout that extends from fragment but of different type, called SongList. My problem is that I have defined this fragment for the class of Cover and when I change I don't have any problem, but when I want to get the

STAMINA mode breaks fragment loading with custom animations

自古美人都是妖i 提交于 2019-12-13 06:19:29
问题 This code is working as expected on all devices except Sony devices with activated STAMINA mode: int backStackCount = getSupportFragmentManager().getBackStackEntryCount(); getFragmentManager() .beginTransaction() .setCustomAnimations(backStackCount == 0? R.animator.noanim : R.animator.slide_in, R.animator.zoom_out, R.animator.zoom_in, backStackCount == 0? R.animator.noanim : R.animator.slide_out) .replace(R.id.container, fragment, String.valueOf(backStackCount)) .addToBackStack(fragment

Commiting FragmentTransaction in 1 Tab of a FragmentPagerAdapter

折月煮酒 提交于 2019-12-13 02:26:16
问题 I'm using FragmentPageAdapter to have multiple tabs within my app. 1 of those tabs is a ListFragment that is supposed to be replaced by another fragment onItemClick , using FragmentTransaction . The change replace works perfectly if I add the ListFragment to a FrameLayout inside an Activity , but I'm not sure how to do this using FragmentPagerAdapter . Here's a better explanation: Tab1 Tab2 Tab3 Tab4 fragment fragment fragment fragment subclass subclass subclass listview after clicking on one

Android App Crashes on FragmentTransaction.replace

杀马特。学长 韩版系。学妹 提交于 2019-12-12 16:51:46
问题 I'm attempting to create a dynamic UI using the support.v4 library to insert fragments into a framelayout I have defined for my main activity. Here is my activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:baselineAligned="false" > <LinearLayout android:layout_width="0dp" android:layout_height="fill

FragmentTransaction add() behavior

烈酒焚心 提交于 2019-12-12 04:54:35
问题 Working with fragments I've always used replace() for my transactions, but I wish I didn't have to save instance states anymore to restore a fragment's view and prevent reloading when coming back to that fragment. So, I've decided to work with add() . The thing is when I add another fragment, the previous fragment view remains in the background and that's fine (that's the behavior I expected), but the problem is I can actually interact with the views in the background. Example: Fragment A has

IllegalArgumentException: No view found for id in fragments

不问归期 提交于 2019-12-12 01:49:36
问题 I tried searching all SO questions but seems its because missing setContentView or need clean the project, my issue its i got java.lang.IllegalArgumentException: No view found for id but its "random" i can't figure out why some devices throw this exception i have Activity->FragmentA->Nested fragment and works great but sometimes after a lot of time when i try to open my app crash this its the code in OncreateView if(savedInstanceState==null) { try { FragmentDestination f = FragmentDestination

Why is getFragmentManager().findFragmentById returning null (causing NullPointerException)

让人想犯罪 __ 提交于 2019-12-11 14:46:36
问题 I have two fragments: input on top, and result on bottom. Initially, only the InputFragment shows. When the user clicks the "Calculate" button, the ResultFragment shows. That all works well. The ResultFragment has a "Clear all" button, which I want to clear the InputFragment's fields, and make ResultFragment go away (hide, remove, or detach, I don't care which, so long as it becomes invisible). But it crashes when you hit "Clear all" button. Specifically, a fatal NullPointerException happens

Manage the backstack in android

老子叫甜甜 提交于 2019-12-11 14:03:25
问题 Currently the structure of the android app is Home About us Products product1 product2 product3 Contact us As there is a side-menu and I can access the product 1 directly, My current attempt is add to backstack for every transaction,and it has a behavior that is quite strange If I go into like this: Home->product1->About us The flow is after I enter the home page, I click on the product1 on the side menu, after enter product1 page click on the about us on the side menu 1st time press back