Android sharepreference data storage stores data in the input box, And sharepreference stores data
Fragment uses a lightweight data storage sharepreference, and the code is clear. Save the data in the input box and click Save.
Simple and clear code for personal projects:
For more information, see:
Class inherits the click event of Fragment implementation:
Public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {// TODO Auto-generated method stub View = inflater. inflate (R. layout. wifi, container, false); view. findViewById (R. id. openwifi ). setOnClickListener (this); view. findViewById (R. id. closewifi ). setOnClickListener (this); wifiurl = (EditText) view. findViewById (R. id. editText1); wificom = (EditText) view. findViewById (R. id. editText2); wificamera = (EditText) view. findViewById (R. id. editText3); // This code source personal blog: http://www.cnblogs.com/xiaobo-Linux/ wavelet Linux qq 463431476 Zhao Archive
SharedPreferences = getActivity (). getSharedPreferences ("wifisetparameters", Activity. MODE_PRIVATE); // private data; String str_wifiurl = sharedPreferences. getString ("wifiurl", "192.168.8.1"); String str_wificom = sharedPreferences. getString ("wificom", "2016"); String str_wificamera = sharedPreferences. getString ("wificamera", "8083"); wifiurl. setText (str_wifiurl); wificom. setText (str_wificom); wificamera. setText (str_wificamera); return view ;}
This code source personal blog: http://www.cnblogs.com/xiaobo-Linux/ wavelet Linux qq 463431476 Zhao Archive
Save data:
Public void savewifisettings () {sharedPreferences = getActivity (). getSharedPreferences ("wifisetparameters", Activity. MODE_PRIVATE); // private data; Editor editor = sharedPreferences. edit (); // get the editor. putString ("wifiurl", wifiurl. getText (). toString (); editor. putString ("wificom", wificom. getText (). toString (); editor. putString ("wificamera", wificamera. getText (). toString (); editor. commit (); // submit changes}
Button save:
@ Override public void onClick (View v) {// TODO Auto-generated method stub switch (v. getId () {case R. id. openwifi: savewifisettings (); // Save the settings when enabling wifi }}
This code source personal blog: http://www.cnblogs.com/xiaobo-Linux/ wavelet Linux qq 463431476 Zhao Archive
View xml data: