SlidingTabLayout不显示在输出上

时间:2015-07-01 18:30:53

标签: android

我正在使用Android Studio 1.2.2并尝试为我的某项活动实施标签。我添加了所有代码,但似乎没有在手机上获得任何输出。我不需要ActionBar,只需要SlidingTabLayout,但是当我跑步时它不会显示除空白屏幕以外的任何内容。

Iphone6Activity.java

package com.hashmi.omar.vodafonestore;


import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class Iphone6Activity extends Activity {



private ViewPager mPager;

private SlidingTabLayout mTabs;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_iphone6);

    //Sets font for text
    //Typeface vodaLt = Typeface.createFromAsset(getAssets(), "VODAFONELT.TTF");
    //TextView vodaHeading = (TextView) findViewById(R.id.textView10);
   // vodaHeading.setTypeface(vodaLt);

    mPager = (ViewPager) findViewById(R.id.ip6pager);

    //mPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));

    mTabs = (SlidingTabLayout) findViewById(R.id.ip6tabs);

    mTabs.setViewPager(mPager);


}




class MyPagerAdapter extends FragmentPagerAdapter{

    String[] tabs;

    public MyPagerAdapter(FragmentManager fm) {
        super(fm);
        tabs=getResources().getStringArray(R.array.tabs);
    }


    @Override
    public Fragment getItem(int position) {
        MyFragment myFragment=MyFragment.getInstance(position);
        return myFragment;
    }


    @Override
    public CharSequence getPageTitle(int position){
        return tabs[position];
    }


    @Override
    public int getCount() {
        return 3;
    }
}

public static class MyFragment extends Fragment{
    private TextView textView;
    public static MyFragment getInstance(int position){
        MyFragment myFragment = new MyFragment();
        Bundle args = new Bundle();
        args.putInt("position", position);
        myFragment.setArguments(args);
        return myFragment;
    }


    @Override

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup     container, @Nullable Bundle savedInstanceState) {
        View layout=inflater.inflate(R.layout.fragment_my, container,     false);
        textView= (TextView) layout.findViewById(R.id.position);
        Bundle bundle=getArguments();
        if(bundle!=null)
        {
            textView.setText("The page selected is "+bundle.getInt("position"));
        }

        return layout;
    }
}

}

activity_iphone6.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/iphone6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.hashmi.omar.vodafonestore.Iphone6Activity"
android:background="#ffffffff">


<com.hashmi.omar.vodafonestore.SlidingTabLayout
    android:id="@+id/ip6tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

<android.support.v4.view.ViewPager
    android:id="@+id/ip6pager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />



</LinearLayout>

fragment_my.xml

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

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您没有使用MyPagerAdapter类。取消注释此行以设置ViewPager的适配器:

//mPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));