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
- string[] arr = new string[] {"str1", "str2"};
- list<string> list = Arrays.aslist (arr);
List conversions to arrays
- list<string> list = new arraylist<string> ();
- List.add ("str1");
- List.add ("str2");
- int size = List.size ();
- 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