I have problem with using EditText with several fragments. I have two fragments: FragmentOne and FragmentTwo, and each fragment has EditText.
After adding FragmentTwo above FragmentOne:
android.support.v4.app.FragmentManager fragmentManager =getActivity().getSupportFragmentManager()
fragmentManager.beginTransaction().add(R.id.frame,new FragmentTwo()).addToBackStack(null).commit;
When I press Enter on keyboard, cursor goes to EditText on FragmentOne. How to fix it? Similar problem was when background fragment was still clickable, but I've solved it. What about this problem?
That is becauase, you are not hiding/removing the previous fragment. identify the previousfragment and hide it before you add the new one.
fragmentManager.beginTransaction().add(R.id.frame,new FragmentTwo()).addToBackStack(null).commit;
this should be
fragmentManager.beginTransaction().add(R.id.frame,new FragmentTwo()).hide([current fragment]).addToBackStack(null).commit;
if you gave a name to your fragment, you can find the fragment by
fragmentManager.findFragmentByName("fragname");
I just bumped into this issue as well. I have a parent fragment and I show and hide a child fragment. There is an editText in the parent fragment which ends up in the back of the child fragment. At the time of displaying the child fragment I went into the fragment layout and set its view to gone, and that removed the focus. Of course if I were to hide the child fragment, then the layout would be visible again.
Related
I am trying to implement bottom sheet behavior to fragment.The two points are need to implents
i)calling one fragment to another when button is clicked.
ii)apply bottomsheet behavior to fragment B,So that When I drag down the fragment can hide/dismiss.
Currently I am having two fragment A,B.I call fragment B in Fragment A by a container When button is clicked .
But when I am trying to implent second point I get error.On FrgmentB I am extend only Fragment not Fragmentdialog. The main reason is I cannot able to acess the background UI.
I have the same problem before, what I did is change the fragment to BottomSheetDialogFragment and made some changes.
If I need to hide a view inside the Activity when a certain fragment is inflated, is it ok to let the Fragment do the State Change?
For example I have a three Fragments (FragmentA, FragmentB, FragmentC) and one Activty. The Activity have a BottomNavigation View but its visibility should be set to Gone if FragmentB is inflated inside the Activity.
If I placed the managing of the BottomNavigation Visibility inside the fragment then, I am sure that whenever that fragment is inflated the view will certainly be set to gone.
My only problem is that, if there come a time that I need to reuse that fragment and show the BottomNavigation at the same time. I wont be able to do so because the Fragment will automatically set the Visibility of the BottomNavigation to Gone.
Can anyone give me some tips? Thanks in advance.
In your case, do not control the visibility of the BottomNavigation inside the Fragment, do it inside the Activity with a callback.
read about callback this in part "Creating event callbacks to the activity"
Fragments should be self-sufficient and should not know anything about other Fragments and Activites.
Im working with fragments on my main activity I have a Edit Text and buttons in my main activity But when I opens fragment page and click exact at the spot of Edit Text the keyboard activates.
So it means the below activity is also in working at same time
Fragments are designed to be inside an activity, if you don't want to make your activity visible you can use a full screen layout for fragment, to remove the clicks you can replace .add command with .replace when transacting to fragments give a background color to the root view of fragment layout also. I think this would help
YourFragment fragment = new YourFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.ll_job_view_fragment_container, fragment)
.addToBackStack(TAG_FRAGMENT_YOUR_VIEW)
.commit();
Edit
The replace may not help, If you inflate different fragments in the same container you just give the attribute android:clickable="true" to the top most parent view of each fragment that will help.
In my android application i have an activity with a view pager, the last one has a fragment pager adapter as adapter with exactly 4 fragments.
Three of the four fragment have edit text on their layout, the problem is that when i'm in the last fragment then touching the screen lead to put focus on the first fragment's edit text !
what is the issue please ?
I have created one fragment from the activity. After that I have added another fragment top of the previous fragment. I have added Android: clickable="true" in my top fragment so that I can grab the click event. Everything is working fine. Now I am trying to implement the external Keyboard navigation and found that bottom fragment still grab the focus.
I have tried different ways to clear the focus of bottom fragment when I am in the top fragment. But could not find a solution.
I solved the issue. I just invisible the bottom fragment from the top using findFragmentBytag to find the bottom fragment.
Example code segment:
Fragment bottom = ( Fragment) getFragmentManager().findFragmentByTag(bottom.TAG);
if (bottom.isVisible()) {
bottom.getView().setVisibility(View.INVISIBLE);
}