Suppose I have a Fragment called Fragment MenuFragment
and it have R.id android:id="@ id/MenuFragment"
inside nav_graph.xml
Question 1: Can I programmatically find R.id if I have just MenuFragment.class
?
Question 2: Can I programmatically get MenuFragment.class
if I have just R.id.MenuFragment
?
CodePudding user response:
No. A fragment can have infinitely many ids. If you have an instance of a fragment you can get its id, but you could have the same fragment in a dozen activities with a dozen different ids. Heck, you can have a dozen copies in the same activity with a dozen ids.
This, yes. If you use the id to get the actual instance of the fragment, you can then use .getClass() to get its class.