I was wanting to use ActionBar tabs and ViewPager to implement swiping between tabs. I have successfully used the example here:
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
However, I also wanted to add a Frame Layout outside of the ViewPager in the xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
<FrameLayout
android:id="@+id/frame_layout"
android:name="com.banagas.calculator.ButtonFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
If I set the setContentView() to my layout with both the ViewPager and Frame Layout, the ViewPager stops functioning:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("MainActivity", "onCreate");
mViewPager = new ViewPager(this);
mViewPager.setId(R.id.FrameLayout1);
ActionBar bar = getSupportActionBar();
mViewPager.setOffscreenPageLimit(4);
bar.setDisplayHomeAsUpEnabled(false);
bar.setDisplayShowTitleEnabled(false);
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mTabsAdapter = new TabsAdapter(this, mViewPager);
mTabsAdapter.addTab(bar.newTab().setText("Display"), DisplayFragment.class, null);
mTabsAdapter.addTab(bar.newTab().setText("Y="), YFragment.class, null);
mTabsAdapter.addTab(bar.newTab().setText("Graph"), GraphFragment.class, null);
mTabsAdapter.addTab(bar.newTab().setText("Table"), TableFragment.class, null);
if (findViewById(R.id.frame_layout) != null)
{
if (savedInstanceState != null)
{
return;
}
getSupportFragmentManager().beginTransaction().add(R.id.frame_layout, new ButtonFragment()).commit();
Log.i("MainActivity", "add.ButtonFragment");
}
}
I can see the tabs and nothing else within the ViewPager. My Frame Layout works perfectly fine though. How would I get ViewPager to work with this?