Data transfer for Android fragment

Source: Internet
Author: User

Bundle Pass Parameters

Fragment1 fragment1 = new Fragment1 ();
Bundle bundle = new bundle ();
Bundle.putstring ("name", "Zhang San");
Fragment1.setarguments (bundle);

Fragmentmanager fm = Getfragmentmanager ();
Fragmenttransaction transaction = Fm.begintransaction ();
Transaction.addtobackstack (NULL);
Transaction.add (R.ID.CONTENT,FRAGMENT1);
Transaction.hide (Homefragment.this);
Transaction.commit ();

It is important to note that the existing fragment is going to use the bundle to pass the parameters.

The acceptance parameters are relatively simple, and half of the time will be considered in the fragment Onattach life cycle to accept.

The code is as follows:

Bundle arguments = getarguments ();
String name = arguments.getstring ("name");
Of course, we'd better have to judge if the value obtained is not NULL, because it is possible to not get the data from the server when there is no network, it will not be accepted here.









Data transfer for Android fragment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.