How to remove focus of a fragment of a back stack?

I use fragments in my application. I have a snippet containing EditText and some Dialogfragment .

When I click on one particular widget, it will move to the next fragment. I need the first snippet in backstack, so I added the addToBackStack method.

The second snippet does not contain an EditText . Now the problem is that when we touch or click on the second fragment, the EditText in the first fragment gets focus and the dialogs go on.

I got the following code

 getView().setFocusableInTouchMode(true); getView().requestFocus(); 

I put this in onResume() . But onResume() will not be called according to some android docs. What should I do? This is a picture of the second action that shows the problem. enter image description here

+7
android focus fragment onresume
source share
2 answers

The solution to my question, instead of adding a fragment, just use a replacement, and one more thing that we can avoid, and by clicking on the layout also

+1
source share

From your question, I realized that your current fragment has no focus

Try to follow

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInnstance) { View view = inflater.inflate(R.layout.your_layout, container, false); view.setOnClickListener(this); return view; } 
0
source share

All Articles