2

是否有机会修改 PagerTitleStrip 以显示所有页面,而不仅仅是三个。基于此,我发现可能没有。但是你能提出任何具有类似作用的替代方案吗?

4

1 回答 1

0

尝试这个。

public class SectionsPagerAdapter extends FragmentPagerAdapter{

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int position) {
        // TODO Auto-generated method stub
        Fragment fragment = new DummySectionFragment();
        Bundle args = new Bundle();
        args.putInt(DummySectionFragment.ARG_SELECTION_NUMBER, position + 1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 2;
    }
    public CharSequence getPageTitle(int position){
        Locale l = Locale.getDefault();
        switch(position){
        case 0:
            return getString(R.string.general).toUpperCase();  \\GET YOUR STRING
        case 1:
            return getString(R.string.Home).toUpperCase(); \\GET YOUR STRING
        case 2:
                return getString(R.string.something).toUpperCase();\\GET YOUR STRING
        case 3:
                return getString(R.string.another).toUpperCase(); \\  DO the SAME IF YOU HAVE MORE STRING
        }
        return null;
    }

}


    public static class DummySectionFragment extends ListFragment{

            public static final String ARG_SELECTION_NUMBER = "section_number";

    public DummySectionFragment(){

    }
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        p = getArguments().getInt(ARG_SELECTION_NUMBER);
        rootView = inflater.inflate(R.layout.viewrow, container, false);

        return rootView;

    }
}
于 2013-09-30T00:45:20.427 回答