改变" hello world from section:1"

时间:2016-08-18 04:15:10

标签: android android-fragments

我在Android上很开心。

当我创建新活动时,我选择选项卡式活动。

如何从以下部分更改" Hello世界:1"每个幻灯片上的差异字符串值。

这是我主要课程的一部分:

public class SectionsPagerAdapter extends FragmentPagerAdapter {

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

    @Override
    public Fragment getItem(int position) {
        return PlaceholderFragment.newInstance(position + 1);
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "SECTION 1";
            case 1:
                return "SECTION 2";
            case 2:
                return "SECTION 3";
        }
        return null;
    }
}

2 个答案:

答案 0 :(得分:2)

您可以在array=echo ${array1[@]}|sed 's/|$//' 中进行更改。在这个演示应用中,您会注意到方法 $time = 1471488076; //08/18/2016 @ 2:41am (UTC) $SECONDS_IN_YEAR = 365 * 24 * 60 * 60; $SECONDS_IN_DAY = 24 * 60 * 60; $SECONDS_IN_HOUR = 60 * 60; $s = $time % $SECONDS_IN_DAY; $hour = floor($s / $SECONDS_IN_HOUR); //$hour = 2 $mins = floor(($s / 60) % 60); //$mins = 41 $seconds = floor($s % 60); //$seconds = 16 echo "TIME >> $hours:$mins:$seconds".PHP_EOL; // 2:41:16 $year = floor(1970 + ($time / $SECONDS_IN_YEAR)); //$year = 2016 。该位置将传递到PlaceholderFragment,并在其基础上将文本设置为其中的PlaceholderFragment.newInstance(position + 1);

您可以为Fragment方法中的每个位置编写一个开关案例,并将文本更改为您想要的任何内容。

答案 1 :(得分:0)

这是我的处事方式,我认为效率很低,但是行得通

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    TextView textView = (TextView) rootView.findViewById(R.id.section_label);
    textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));


    int NumberOfArguments;
    NumberOfArguments = getArguments().getInt(ARG_SECTION_NUMBER);

    //inicio

    switch (NumberOfArguments) {
        case 1:
            // CREATE TEXTVIEW IN fragment_main ID: mesagge  //Change number of tabs in the end of the MainActivity in: public int getcount{}  - return 
            View rootView2 = inflater.inflate(R.layout.fragment_main, container, false);
            TextView textView2 = (TextView) rootView2.findViewById(R.id.mesagge);
            textView2.setText("This ");
            return rootView2;

        case 2:
            View rootView3 = inflater.inflate(R.layout.fragment_main, container, false);
            TextView textView3 = (TextView) rootView3.findViewById(R.id.mesagge);
            textView3.setText("Is A");
            return rootView3;

        case 3:
            View rootView4 = inflater.inflate(R.layout.fragment_main, container, false);
            TextView textView4 = (TextView) rootView4.findViewById(R.id.mesagge);
            textView4.setText("Good Time");
            return rootView4;

        case 4:
            View rootView5 = inflater.inflate(R.layout.fragment_main, container, false);
            TextView textView5 = (TextView) rootView5.findViewById(R.id.mesagge);
            textView5.setText("TO Learn");
            return rootView5;


        case 5:
            View rootView6 = inflater.inflate(R.layout.fragment_main, container, false);
            TextView textView6 = (TextView) rootView6.findViewById(R.id.mesagge);
            textView6.setText("Code");
            return rootView6;

    }

    return rootView;
}