fragmentmanager

FragmentTransaction won't Compile in Kotlin Android Project

孤者浪人 提交于 2019-12-14 01:31:01
问题 In the process of learning Kotlin with Android, the failure to compile and generally unhelpful error text have left me stumped. The error text says the following: None of the following functions can be called with the arguments supplied. add(Fragment!, String!) defined in android.app.FragmentTransaction add(Int, Fragment!) defined in android.app.FragmentTransaction In both instances the Fragment! text is highlighted in red. I am aware that Kotlin refers to Java classes with an !, but I can't

Android onBackStackChanged() not called

无人久伴 提交于 2019-12-14 00:18:45
问题 I have an Activity like the code below: public class AuthenticatedMainActivity extends Activity implements FragmentManager.OnBackStackChangedListener{ @Override protected void onCreate(Bundle savedInstanceState) { ............. FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().add(R.id.frame_container,fragment, "First").addToBackStack(null).commit(); } private void switchFragment(Fragment fragment){ FragmentManager fragmentManager = getFragmentManager(

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

android toolbar color is turning to blue when come from fragment

二次信任 提交于 2019-12-13 02:51:09
问题 I have an app that works without problems.In this app, I display the products from the server.When you click on one of the products, we enter the details activity to show details.Everything works fine.But when I go to this activity from one of the other pages of the program, which is a fragment(an activity with tab and view pager and fragments) .The color of the toolbar and the imageview that is white is changed to blue help me please it is my fragment code: public class CatFragment extends

Fragment - replace container, if id is not unique

本秂侑毒 提交于 2019-12-12 18:28:48
问题 I have a layout that has two views with the same id. If I want to find the view I just call parentView1.findViewById(R.id.content) or parentView2.findViewById(R.id.content) to get the correct view. If I want to replace a container with a fragment, can I somehow define which one I want to be replaced? 回答1: Fragment manager accepts only id, so, i think, answer is no, you cannot specify container. But you still can found both of them. As a workaround you can wrap your containers with fragments

How to pass variables with Android fragmentmanager [duplicate]

眉间皱痕 提交于 2019-12-12 16:42:16
问题 This question already has answers here : How to pass a variable from Activity to Fragment, and pass it back? (7 answers) Closed 3 years ago . I have the following simple code to switch from one fragment to another in the content frame. Is there a simple way to pass variables in the following code? FragmentManager fm = getActivity().getFragmentManager(); fm.beginTransaction().replace(R.id.content_frame, new TransactionDetailsFragment()).commit(); 回答1: You can use Bundle: FragmentManager fm =

android: getFragmentManager() returns null

放肆的年华 提交于 2019-12-12 16:09:55
问题 Edit: The problem is that the fragment is getting detached from the Activity. However, I don't know how to prevent this. I have an application that uses a tab bar. When one of the tabs is clicked it loads a list of topics in the space below the tab bar. One of the topics is 'Directions'. Upon clicking this the space is now replaced with a layout that has another bar at the top (below the tab bar) that includes a 'Back' button and a 'Get Directions' button. Below that bar is a google map of

Reloading fragment, Edittext's text not cleared

99封情书 提交于 2019-12-12 14:57:28
问题 In my fragment there are lot of spinner and edit text and submit button is to save data, reset button is to reset all elements(Edit Texts and Spinners). I have used folllowing code to reset all controls FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.detach(this).attach(this).commit(); but it doesn't clear editext. All spinners are reset but editext's text remain as it is 回答1: detach().detach() not working after support library update 25.1.0 (may be earlier). This

Ignoring navigate() call: FragmentManager has already saved its state

為{幸葍}努か 提交于 2019-12-12 09:38:25
问题 I'm using navigation in MainActivity , then I start SecondActivity (for result). After finish of SecondActivity I would like to continue with navigation in MainActivity , but FragmentManager has saved his state already. On Navigation.findNavController(view).navigate(R.id.action_next, bundle) I receive log message: Ignoring navigate() call: FragmentManager has already saved its state How I can continue in navigation? 回答1: You must always call super.onActivityResult() in your Activity's

FragmentStatePagerAdapter returns wrong positions in getItem

巧了我就是萌 提交于 2019-12-12 04:33:44
问题 I'm using a FragmentStatePagerAdapter . The getItem(int position) returns wrong positions. I have 5 fragments. This is the position when I change the fragments: Fragment0 -> Fragment1: position = 2 Fragment1 -> Fragment2: position = 3 Fragment2 -> Fragment3: position = 4 Fragment3 -> Fragment4: getItem is not called! Fragment4 -> Fragment3: position = 2 Fragment3 -> Fragment2: position = 1 Fragment2 -> Fragment1: position = 0 Fragment1 -> Fragment0: getItem is not called! Here is the code for