Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Previous fragment edittext focus issue

I am using multiple fragments. I am adding fragment over fragment as below

supportfragmentmanager
            .beginTransaction()
            .add(R.id.container_login, newFragment, newFragment.javaClass.simpleName)
            .addToBackStack(newFragment.javaClass.simpleName)
            .commitAllowingStateLoss()

Now the issue is, despite of adding new fragment, previous fragment is not losing focus. Typing in edittext of current fragment types in previous fragment edditext.

Even action next also loses focus in current fragment and moves cursor in previous fragment.

Kindly help.

like image 895
Vir Rajpurohit Avatar asked Dec 02 '25 09:12

Vir Rajpurohit


1 Answers

The fragment does not lose focus because you use .add method which adds the new fragment over the one which already exists in the container. Use .replace() method which replaces the existing fragment from the container. This is similar to calling remove(Fragment) and then use .add() method.

like image 134
Stefan Olteanu Avatar answered Dec 03 '25 23:12

Stefan Olteanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!