So basically,
I'm using the slidingTabLayout and slidingTabStrip
I have a ViewPager:
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
></android.support.v4.view.ViewPager>
Which gets filled with a adapter on my MainActivity.java:
private ViewPager pager;
private TabsViewPagerAdapter adapter;
private SlidingTabLayout tabs;
protected void onCreate(Bundle savedInstanceState) {
adapter = new TabsViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true);
tabs.setViewPager(pager);
}
The TabsViewPagerAdapter returns a Fragment, depending on the tab position:
public Fragment getItem(int position) {
if(position == 0)
{
PersonalTab tab1 = new PersonalTab();
return tab1;
}
else
{
GroupTab tab2 = new GroupTab();
return tab2;
}
}
finally, each fragment contains this simple layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/personal_tab">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The tabs are rendering pretty well and working. Now I have two questions since I'm newbie:
How can I access this fragment from the main activity so I can change the inner textView text for example?
In case it is possible to access the fragment, is it better to replace the fragment for data changes or dynamically change the data inside?