Java fragment call conversion to Kotlin

-2

I am creating an app that will have a main activity and some fragments interleaved, in that case I am trying to launch a fragment_main but I can not frazer this Java code flipping code Koltin:

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
UsuarioCadFragment fragment = new UsuarioCadFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();

This code should be called soon in the creation of the main activity, but in kotlin.

    
asked by anonymous 20.09.2018 / 03:34

1 answer

0

The getFragmentManager() method is deprecated from the API level 28. It is recommended to use the getSupportFragmentManager() method instead, or, using kotlin's property access syntax, you can simply access it as supportFragmentManager .

One way to do this is what you're trying to do:

val tx = supportFragmentManager.beginTransaction()
tx.replace(R.id.fragment_container, UsuarioCadFragment())
tx.commit()
    
23.09.2018 / 04:30