fragmentmanager

Reload or notify Fragment's data in ViewPager

强颜欢笑 提交于 2019-12-05 22:18:21
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 and I cant add new one, just make .atach([main]Fragment) for current... Reload activity is bad idea.

Replacing fragments in an activity not calling onAttach, onCreate, onCreateView, etc

坚强是说给别人听的谎言 提交于 2019-12-05 04:26:25
So I have this piece of code here, I am creating a new Fragment and replacing it with another fragment. That works well. However I have notice that on the first line the constructor is being called but the onAttach() , onCreate() etc are not. If I were to uncomment the second line it won't work as updateItem(URL) requires a webView that is initiated in the onCreate() function. DetailViewFragment detailFragment = new DetailViewFragment(); //detailFragment.updateItem(URL); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.displayList, detailFragment); ft

How to set a Tag to a Fragment in Android

核能气质少年 提交于 2019-12-05 01:12:55
I've looked at all the questions on Stackoverflow but could not find a single definitive answer to this question. How do you set a Tag to a Fragment so that you can retrieve it via getFragmentManager().findFragmentByTag() ? Could someone give a simple code example of how to create a tag to a Fragment ? You can set a Tag during fragment transaction. For example if it's a replace transaction you could do it like so: FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.fragment_container, mFragment, TAG) .commit(); If the Fragment you're

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

烈酒焚心 提交于 2019-12-04 12:31:02
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 this activity was started with special instructions from an Intent, // pass the Intent's extras to the

android.support.v4.app.FragmentManager OR android.app.FragmentManager?

喜你入骨 提交于 2019-12-04 11:11:27
问题 I'm learning Android development. I get stuck at something that should be very easy. Im creating an App with one Activity, 2 fragments and 1 interface. android:minSdkVersion="11" android:targetSdkVersion="19 So in the main activity Im trying to create a reference to Fragment B using the manager. I get stuck here, because Eclispse is telling me to change some things (see below): My intension:` @Override public void respond(int i) { // TODO Auto-generated method stub FragmentManager manager

How to keep the same fragment when activity restarts due to orientation change in a Navigation Drawer Activity

做~自己de王妃 提交于 2019-12-04 10:35:33
I found many post explaining how get the Fragment from the savedInstanceState Bundle but, because the Activity can swap between 4 Fragments , i need a way to know which Fragment was alive before rotate when the orientation started to change. The reason i have several Fragments is because i am using Navigation Drawer, so each menu item as a fragment. I had the same issue and I fixed it adding this to the Navigation Drawer activity code: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(savedInstanceState==null){ //Handle the initial fragment transaction

Android: master/detail flow (dual-pane) using 1 activity

假装没事ソ 提交于 2019-12-04 09:30:59
问题 As reported by the Android guide, dual-pane can be achieved in two ways: Multiple fragments, one activity Multiple fragments, multiple activities I am using the first case (the Android guide only explains the second case). This is what happens on 7" tablets : rotating from landscape to portrait : only the single-pane fragment gets recreated rotating from portrait to landscape : all 3 fragments (single-pane, dual-pane-master, dual-pane-detail) get recreated Question: why is the single-pane

Is there a way to listen to FragmentTransactions of a FragmentManager?

為{幸葍}努か 提交于 2019-12-04 07:11:52
问题 I have an app with several Fragments which interact to each other. Sometimes I have to add a Fragment , sometimes I replace it. Is there a way to listen to FragmentTransactions completed, so I can keep track of every time a Fragment is added/shown/replaced? I've tried fragmentManager.addOnBackStackChangedListener() but unsuccessfully. I thought of doing something on the onResume() of all of them, but if the app goes to background and foreground I should not do anything to my UI. Only when I

getBackStackEntryCount() always returns 0 even after adding addToBackStack and executePendingTransactions()

孤街浪徒 提交于 2019-12-03 22:30:01
I have two activities A and B. Activity A has a mapFragment and I am adding it to backstack. When I come back from to Actvity A from B, I want the fragment to show up in same state as I left it. But getFragmentManager().getBackStackEntryCount() is returning me 0. Here is my code: MapFragment mMapFragment = MapFragment.newInstance(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); mMapFragment.getMapAsync(this); fragmentTransaction.replace(R.id.container, mMapFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); getFragmentManager(

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) {