fragmenttransaction

When to use the attach and detach methods of FragmentTransaction

元气小坏坏 提交于 2019-11-27 17:24:24
I just went through the documentation of the attach() and detach() methods of FragmentTransaction : attach() : Re-attach a fragment after it had previously been detached from the UI with detach(Fragment) . This causes its view hierarchy to be re-created, attached to the UI, and displayed. Well, what does that mean? More specifically, I saw an example: mMapFragment = new MapFragment(); ft.beginTransaction(mMapFragment) .attach() .add(R.id.container, mMapFragment) .commit(); I deleted the attach() and tried again: I did not notice any difference. What does the attach do in this example? What is

Android FragmentTransaction commit already called

回眸只為那壹抹淺笑 提交于 2019-11-27 17:07:28
问题 My ERROR : java.lang.IllegalStateException: commit already called My CODE: final FragmentTransaction fragmentTransaction =getFragmentManager().beginTransaction(); f1_fragment = new F1_Fragments(); f2_fragment = new F2_Fragments(); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { parent.getItemAtPosition(position); if(position==0){ fragmentTransaction.replace(android.R.id.content

What does FragmentManager and FragmentTransaction exactly do?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 05:10:19
问题 I have simple code below FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, mFeedFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); What do these lines of code do? 回答1: getFragmentManager() Return the FragmentManager for interacting with fragments associated with this activity. FragmentManager which is used to create

findFragmentByTag() returns null after perform a FragmentTransaction using replace() method

早过忘川 提交于 2019-11-27 04:12:01
My Android app consists three fragments: A, B and C . They're loaded in the two containers defined in the MainActivity layout. When the app is started, it shows the fragmentA loaded in the left_container and the fragmentC in the right_container . If you press the button in the fragmentA , a FragmentTransaction changes FragmentC by FragmentB . At the moment everything OK. But the trouble appears when I try to get a reference to the loaded fragmentB using findFragmentByTag() , because it returns null . I've used the method replace in the FragmentTransaction and I've finished it with commit() ,

DrawerLayout's item click - When is the right time to replace fragment?

为君一笑 提交于 2019-11-26 23:56:44
问题 I'm developing an application which uses the navigation drawer pattern (With DrawerLayout). Each click on a drawer's item, replaces the fragment in the main container. However, I'm not sure when is the right time to do the fragment transaction? When the drawer starts closing? Or after it is closed? In google's documentaion example, you can see that they are doing the transaction right after the item click, and then close the drawer. As a result, the drawer seems laggy and not smooth, and it

java.lang.IllegalArgumentException: No view found for id 0x1020002 (android:id/content) for fragment

老子叫甜甜 提交于 2019-11-26 20:32:42
问题 I am trying to move from one fragment to another.. It shows following error during fragment transaction- java.lang.IllegalArgumentException: No view found for id 0x1020002 (android:id/content) for fragment PhotosFragment2{41a57218 #3 id=0x1020002} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:930) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at

Navigation Drawer lag on Android

本小妞迷上赌 提交于 2019-11-26 19:45:45
问题 I'm having a problem with Navigation Drawer , it is too slow, the solution I'm looking for is to close the drawer first and then show the activity, but It is not working, certainly I'm missing something. private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int posicao, long id) { setLastPosition(posicao); setFragmentList(lastPosition); layoutDrawer.closeDrawer(linearDrawer); } } private

When to use the attach and detach methods of FragmentTransaction

给你一囗甜甜゛ 提交于 2019-11-26 18:57:16
问题 I just went through the documentation of the attach() and detach() methods of FragmentTransaction : attach() : Re-attach a fragment after it had previously been detached from the UI with detach(Fragment) . This causes its view hierarchy to be re-created, attached to the UI, and displayed. Well, what does that mean? More specifically, I saw an example: mMapFragment = new MapFragment(); ft.beginTransaction(mMapFragment) .attach() .add(R.id.container, mMapFragment) .commit(); I deleted the

Fragment lifecycle - which method is called upon show / hide?

泄露秘密 提交于 2019-11-26 18:55:10
问题 I am using the following method to switch between Fragments (in my NavigationDrawer) by showing / hiding them. protected void showFragment(int container, Fragment fragment, String tag, String lastTag, boolean addToBackStack ) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); if ( lastTag != null && !lastTag.equals("")) { Fragment lastFragment = fragmentManager.findFragmentByTag( lastTag ); if ( lastFragment !

findFragmentByTag() returns null after perform a FragmentTransaction using replace() method

拜拜、爱过 提交于 2019-11-26 12:43:25
问题 My Android app consists three fragments: A, B and C . They\'re loaded in the two containers defined in the MainActivity layout. When the app is started, it shows the fragmentA loaded in the left_container and the fragmentC in the right_container . If you press the button in the fragmentA , a FragmentTransaction changes FragmentC by FragmentB . At the moment everything OK. But the trouble appears when I try to get a reference to the loaded fragmentB using findFragmentByTag() , because it