public void
savepreferences(String name, Integer age) {
-->> Get sharedpreferences
Sharedpreferences preferences = context.getsharedpreferences ("Itcase", context.mode_private);
You do not need to specify the XML suffix name of the filename because the system knows it is an XML file and Android is automatically added;
Editor Editor = Preferences.edit ();//data stored in memory;
Editor.putstring ("name", name);
Editor.putint (' age ', age);
Editor.commit ()//must use this method to submit the intrinsic data back to the file
}
Public map<string, string> getpreferences() {
map<string, string> map = new hashmap<string, string> ();
Sharedpreferences preferences = context.getsharedpreferences ("Itcase",
context.mode_private);//You do not need to specify an XML suffix name because the system knows it is an XML file;
Map.put ("Name", Preferences.getstring ("name", "Default value"));//If no argument exists, the default value is returned
Map.put ("Age", String.valueof (Preferences.getint ("age", 0));
return map;
}
-->> Get Sharedpreferences
This.getpreferences (mode);//By default, the name of the activity is used as the name of the XML;
Preferencemanager.getdefaultsharedpreferences (context);
******************************************************
android:onclick= "Save" <!--is used to specify a method name, which needs to be defined in the acvitity that displays the interface, and requires the Save method to be the same as its own OnClick signature, as follows! -->
View.onclicklistener () {
public void OnClick (View v) {}
}
The definition in public void Save (View v) {}//activity;
android:numeric= "integer" <!--set Numeric type-->