简体   繁体   中英

How to parse value from Activity to Fragment?

How to pass value from Activity to Fragment? I hope someone can help.

In Activity

Bundle bundle=new Bundle();
bundle.putString("name", "From Activity");
//set Fragmentclass Arguments
Fragmentclass fragobj=new Fragmentclass();
fragobj.setArguments(bundle);

Fragment onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
      String strtext=getArguments().getString("name");

return inflater.inflate(R.layout.fragment, container, false);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM