Situation: How to access a variable in activity from a fragment? Maybe chance you have to another way or requirement, then you have to choose as per needs. MyFragment.receiveMsg("Hi Fragment how are you ?") MyFragment myFragment = (MyFragment) manager.findFragmentById(R.id.myfrag) Method in fragment //Receive message - activity to fragmentĬreate an instance in activity and pass data to fragment FragmentManager manager = getSupportFragmentManager() it’s a flexible way when the fragment is already launched and Fragments want data from an Activity. Its very easy to do, create a method in Fragments and in Activity create an instance of fragments and pass data in methods.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |