Adding a fragment on top of another fragment and clear focus of bottom fragment - android

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);
}

Related

problem with viewpager2 and bottomnav working together in android studio

so I'm trying to make small application type of thing where it has bottom navigation bar and viewpager2 working in it. But I want it so that in the first fragment page that application loads in, only there viewpager2 is available to work and be able to swipe, when I switch to next fragment with navigation bar that viewpager2 should basically disappear and not work, therefore my logic was to put that viewpager2 in that single fragment and navigation bar outside in main activity for it to be able to be seen in every fragment. But there is a problem, it almost works, I switch to another fragment with bar view pager disappears but when I go back to that first fragment view pager is just gone, disappeared and I have no idea what's the problem. if necessary I can show what I have written. Thanks in advance

Implement bottomSheet behavior in fragment

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.

Parent fragment destroyed with shared element transition

I have a view hierarchy such as below.
MainActivity :
FirstFragment :
SecondFragment :
In my SecondFragment, i have a RecyclerView. When an item is clicked, i want to open it in another Fragment (in full screen) so i am using the addSharedElement() method and everything works fine after 2 days of retro engineering it : every post i have found on StackOverFlow does not mention that in order to work, the "full-screen" fragment has to replace the first parent inside the activity.
What i first wanted was to nested the full-screen fragment inside the SecondFragment but it's impossible with this method.
I have tried everything else, at each steps of my view hierarchy & none of them is working, except if i replace my FirstFragment by my full-screen fragment.
This is also impossible to use the transition with the add() method unfortunately.
The problem is that this fragment is destroyed & not recreated despite the call of addToBackStack(), when i press the "back-button" inside the NavigationBar.
I am not really familiar with the addToBackStack() method & how can i get back any fragments i have added there.
QUESTION 1 : How can i make it work either without destroying the parent fragment (FirstFragment in my view hierarchy), or without using shared element transition but achieving the same result ?
It seems that what the Transition is doing is recreating a view in the new fragment with the same width / height, x & y coordinates as the one in the previous fragment & animate it from the new fragment...
QUESTION 2 : Would it be a bad idea to do it myself ?
EDIT : My goal is to close the full-screen fragment with a swipe down and as soon as the finger is moved from 10dp along the Y axis, i want to be able to reveal the previous fragment behind (the SecondFragment in my case), that's why i don't want to destroy parent fragments.

switching between fragments delete the views in first fragment

I have in my app a drawer navigation, which contain few fragments to go to. when my app starts it opens by default the first fragment - which contains a view pager that has 2 fragments in it as well. in those 2 fragments I have a text view and a button as well.
the problem is that if I click on another fragment in the drawer, and then go back to the first fragment, the button and the text view are gone. in the first time this view pager fragment is creating the two other fragments. I think that when I go back to this fragment again by replacing it, it wont load the other two fragments and their text and button view. I'm going crazy because of this and I cant continue my work..what is wrong here?
I don't know how to upload code snippets..sorry
Thank you for your help :)

Edittext on background fragment still editable

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.

Categories

Resources