如何在android中的ViewPager的TextView.setText中使用ArrayString?

问题描述 投票:0回答:1

我想在我的Android应用中使用TabActivity。每个viewPager的页面包含2个TextView和1个ImageView。我想用ArrayString而不是简单的String写下文本,但是我不知道如何在TextView.setText中调用它?

我的片段类:

public static class PlaceholderFragment extends Fragment {
    private static final String ARG_SECTION_NUMBER = " " ;
    public TextView label_TV, info_TV;
    public  ImageView photo_IMG;


    public PlaceholderFragment() {
    }


    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_bio, container, false);

        label_TV = (TextView) rootView.findViewById(R.id.section_label);

        //label_TV.setText(?);

        info_TV = (TextView) rootView.findViewById(R.id.section_info);
        photo_IMG = (ImageView) rootView.findViewById(R.id.section_image);
        return rootView;
    }
}

FragmentPagerAdapter类:

public class SectionsPagerAdapter extends FragmentPagerAdapter {

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

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).
        return PlaceholderFragment.newInstance(position + 1);
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:

                return "SECTION 1";

           ..
                          }
        return null;
    }
}

字符串文件:

<string-array name="titles">
    <item>00</item>
    <item>11</item>
</string-array>

我如何将titles arrayString用于label_TV

我想在我的Android应用中使用TabActivity。每个viewPager的页面包含2个TextView和1个ImageView。我想用ArrayString而不是简单的String写下我的文本,但我不知道如何...

android android-fragments textview android-viewpager tabactivity
1个回答
0
投票

大概,最好的方法是通过newInstance()

© www.soinside.com 2019 - 2024. All rights reserved.