I have a fragment that implements an onClickListener
, and then the onClickListener
tries to remove a fragment.
I get a red line under badFragment
in transaction.remove(badFragment);
. My best guess is because it can't tell what that fragment is/where it is.
How would I go about finding that fragment, so that it can be removed?
I've tried findFragmentId(badFragment); but it doesn't work.
Bonus points if you can let me know where you found this method. As I'm not great at looking up things in the Android Docs.
You can find fragment
getFragmentManager().findFragmentById(R.id.fragment_id);
or
getFragmentManager().findFragmentByTag("tag");
you can remove fragment itself
getActivity().getFragmentManager().beginTransaction().remove(this).commit();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.