Android Studio 默认选项卡式活动中的每个片段中的不同数据



我已经使用默认选项卡式活动创建了一个项目,并具有4个选项卡。片段仅包含一个文本框,我想根据当前标签更改其内容。

这是我的 oncreateview 方法看起来像:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        int i = getArguments().getInt(ARG_SECTION_NUMBER);
        TextView textView = (TextView) rootView.findViewById(R.id.txtView);
        switch (i)
        {
            case 1:
                textView.setText("The first");
            case 2:
                textView.setText("The second");
            case 3:
                textView.setText("The third");
            case 4:
                textView.setText("The fourth");
        }

        return rootView;
    }

这里的问题是所有选项卡中的文本框显示第四不管我当前使用哪个标签。

如何解决此问题?

您做错了这一切。您可以在网上有许多教程。以下是一个很好的例子,可以很好地解释。让我知道您是否在链接后是否需要进一步的帮助。

android tableOut示例

最新更新