在主活动中调用片段

阿里沙兹尔

我为每个类别设置了不同的 Fragment,并希望在从抽屉中选择时显示它们

private static final String ARG_POSITION = "position";

    private int position;
    private LinearLayout layout;
    private TextView icon;

    public static WizardUniversalFragment newInstance(int position) {
        WizardUniversalFragment f = new WizardUniversalFragment();
        Bundle b = new Bundle();
        b.putInt(ARG_POSITION, position);
        f.setArguments(b);
        return f;
    }

我该如何解决这个问题?

艾哈迈德·穆吉塔巴

你可以通过它们的位置来调用每个片段。

从您的代码中,我了解了您的位置参数的声明,使用它来调用每个 Fragment

 @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            position = getArguments().getInt(your_pos);
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_wizard_universal,
                    container, false);
            layout = (LinearLayout) rootView
                    .findViewById(R.id.Your_fragment);
            icon = (TextView) rootView
                    .findViewById(R.id.Your_fragment_icon);

            if (position == 0) {
                layout.setBackgroundColor(ContextCompat.getColor(getContext(),
                        R.color.#));
                layout.invalidate();
                icon.setText(R.string.#);
            } 

            ViewCompat.setElevation(rootView, 50);
            return rootView;
        }

设置好,你就可以开始了

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章