Value sharing solution between Android activity, sharing parent class values between tabhost

Source: Internet
Author: User

1.tabhost solution for sharing parent class values

Dianzhanliebiao.java is a value-Zhuyemian.java page, and the Tabhost,dianzhangaikuang.java is the specific sub-layout of Tabhost.

First Dianzhanliebiao.java the value of the pass

Intent.putextra ("id", "1234");
Intent.setclass (Dianzhanliebiao.this, Zhuyemian.class);
Dianzhanliebiao.this.startActivity (Intent);


Zhuyemian.java get the value from Dianzhanliebiao.java
Intent=getintent ();
String Id=intent.getstringextra ("id");

Dianzhangaikuang.java gets the ID in the following ways:

Intent Intent = GetParent (). Getintent ();
String id = intent.getstringextra ("id");

2.activity between the values, personal feeling with sharedpreferences better, but need to declare a global variable (can also be used for value sharing between tabhost)

Generally built a constant class, I am Constant.java

In the declaration public static sharedpreferences Sharedata;

Zhuyemian.java Pass-through value

Constant.sharedata =getsharedpreferences ("Rixin", 0);//The first parameter is the name of the store, and the second argument is how the file is opened
Editor Editor=constant.sharedata.edit ();
Editor.putstring ("id", "1234");
Editor.commit (); A little to commit, or else the page can't get

Fadianliang.java Getting Data

Constant.sharedata=getsharedpreferences ("Rixin", 0);
String id=constant.sharedata.getstring ("id", NULL);

3. String reshaping

Integer.parseint (string,10);//String converted to 10 binary

Double.parsedouble (string);//string converted to double

string.valueof (100);//plastic change to string

Array conversion to List

    1. string[] arr = new string[] {"str1", "str2"};
    2. list<string> list = Arrays.aslist (arr);

List conversions to arrays

    1. list<string> list = new arraylist<string> ();
    2. List.add ("str1");
    3. List.add ("str2");
    4. int size = List.size ();
    5. String[] arr = (string[]) List.toarray (new string[size]); The second interface is used, and the return value and parameters are both results

4. Get the item content for each ListView

Get the contents of each item, I am a custom ListView with TextView control inside it
Tv_name= (TextView) View.findviewbyid (r.id.tv_name);
String Dzmc=tv_name.gettext (). toString ();

Value sharing solution between Android activity, sharing parent class values between tabhost

Related Article

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.