Activity向Fragment传递数据的方法

版权声明:转载请在开头注明博客原地址,谢谢! https://blog.csdn.net/qq_35928566/article/details/82111485

1、使用setAgruments

使用方法
Activity中:

    Fragment  fragment = new Fragment();
    Bundle bundle = new Bundle();
    bundle.putString("something_key", "something_value");
    fragment.setArguments(bundle);

Fragment中:

    onCreateView{
        Bundle bundle = getArguments();
        String something = bundle.getString("something_key");
    }

这样就在创建的时候将activity中的数据传递给fragment了,是不是很简单。

猜你喜欢

转载自blog.csdn.net/qq_35928566/article/details/82111485