活动中片段内的水平滚动选项卡

时间:2015-05-28 20:20:23

标签: android android-layout android-fragments android-activity

我需要在已创建的Fragment内的Activity内实现水平可滚动选项卡。但是Inventory类自然会延伸Fragment,如果我尝试从FragmentActivity扩展Inventory,它就无法工作。

在这里面: enter image description here

这样的东西: enter image description here

import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Inventory extends FragmentActivity {

    ViewPager viewPager = null;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.inventory);
        viewPager = (ViewPager) findViewById(R.id.pager);
        FragmentManager fragmentManager = getSupportFragmentManager();
        viewPager.setAdapter(new MyAdapter(fragmentManager));
    }
}



class MyAdapter extends FragmentPagerAdapter {

    public MyAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public android.support.v4.app.Fragment getItem(int position) {
        android.support.v4.app.Fragment fragment = null;
        if (position==0){
            fragment = new Fa();
        }
        if (position==1){
            fragment = new Fb();
        }
        if (position==2){
            fragment = new Fc();
        }
        return fragment;
    }

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

}

另外,我正在使用this tutorial来实现标签。

0 个答案:

没有答案