Skip to content Skip to sidebar Skip to footer

Android Navigation Drawer Unable To Settext In A Fragment From Mainactivity

I am trying to put GPS coordinates on TextView of a Fragment from MainActivity but I can not figure out how to do this. I have: MainActivity.java LocationFragment.java I want to u

Solution 1:

You can use Interface for it so main objective of Fragment re-usability is maintained. You can implement communication between Activity-Fragment OR Fragment-Fragment via using following :

enter image description here

Solution 2:

its very simple, just create one method in fragment like below,

publicvoidSetTitle() {
        text_title.setText("hello fragment");
    }

now call that method from Activity, below code it for <= ANDROID API 11

HomeFragmentfragment= (HomeFragment) getSupportFragmentManager()
                        .findFragmentByTag("HomeFragment");
                fragment.SetTitle();

for > 11 API just change getFragmentManager()

now you can do whatever you want.

Post a Comment for "Android Navigation Drawer Unable To Settext In A Fragment From Mainactivity"