Fragment setArguments&getArguments的作用

Fragment setArguments&getArguments的作用

  1. 使用说明
    在创建Fragment之前,可以通过setArguments设置Bundle类型参数,在Fragment回调onCreateView里面可以解析该参数,所以可以通过该方法在创建/使用Fragment之前传递参数

注:Bundle是一个键值对

  1. 官方文档说明
    setArguments:
    public void setArguments (Bundle args)
    Supply the construction arguments for this fragment. This can only be called before the fragment has been attached to its activity; that is, you should call it immediately after constructing the fragment. The arguments supplied here will be retained across fragment destroy and creation.

getArguments:
Return the arguments supplied when the fragment was instantiated, if any.

你可能感兴趣的:(Android)