Quillion
Quillion

Reputation: 6476

Tabs within a view

I am learning android views and am currently using a table view. I have separated the screen into 3 section. As shown below.

enter image description here

The only problem that I have seem to run into is tabs. Should I use toggle buttons instead of the tabs and simply show/hide given row of the table based off of which button is toggled? Is there any way to have tabs midview without it affecting the whole activity if tab is switched?

Upvotes: 1

Views: 68

Answers (1)

mmlooloo
mmlooloo

Reputation: 18977

if you want to have midview tabs you need:

https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.htm

in order to implement them look at the sample demo in the project file. but quick example:

copy all classes in view folder to your project then you can do something like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">

    <com.example.android.common.view.SlidingTabLayout
          android:id="@+id/sliding_tabs"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="0px"
          android:layout_weight="1"
          android:background="@android:color/white"/>
</LinearLayout>

and in your fragment or activity:

mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
mViewPager.setAdapter(new MyAdapter());
mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setViewPager(mViewPager);

your adapter of mViewPager must override below method

@Override
        public CharSequence getPageTitle(int position) {
            return your tab title;
        }

Upvotes: 3

Related Questions