I have activity_main which is default layout in my activity, there i have framelayout which display fragment whit different layout, is it possible to connect the different layout textview to setText() from my activity? How to connect from activity to this fragment xml layout?
activity_main
frameLayout
fragment 1 xml
fragment 2 xml
/frameLayout
Activit.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dirShow("a");
}
void dirShow(String s) {
setContentView(R.layout.fragment1);
textPath = (TextView) findViewById(R.id.path_text);
textPath.setText(s);
}
You shouldn’t be calling setContentView more than once in an activity. The content view is the entire activity layout. If you want to change the layout the proper way to do it is to change the fragment or activity, and have the new activity or fragment show the new layout.
If you’re not trying to change layouts, then just put the TextView you need in the first layout that you set. Posting your layout files and telling us what you’re trying to do may allow us to help you achieve what you want.
EDIT:
If I understand your updated question correctly, you’re using Fragments. If that’s the case, call the dirShow() function in the Fragments onCreateView() function instead of the activity’s onCreate() function.
If you’re just incorrectly using the term fragment in your question, I suggest you switch to using them.