Vtg

SUiistrfliU . nm%m lM^ 8-2 ftf/j-. & main.xml iff "VI1

"t" LinearLayout '^'jftT 3 TextView flWf- EditView HMf, Kfiif/j<:

♦ J; DBSheredPreferences.jeve ♦ Android I 1

- VftlttOS

X siring« xal Ct Androidi&nifest xi»l default, properties

<?xml version-" 1.0" encoding="utf-8"?>

<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android" Android:or1entat i on = "vert ica1" Android:layout_width="f ili_parent"

Android: layout_height="fill parent."

<TextView

Android:layout width="fi11 parent" Android: layout, hei ght- "wrapcontent " Android:text "SharedPreferences demo" />

<TextView Android:layout width="fill_parent" Android:layout height="wrap_content" Android:text="Name:" /> <EditText Android: id-"^-» id/name" Android:layout width-"fill parent" Android:layout height="wrap_content" Android:text»"" />

<TextView Android:layout width "fill parent" Android:layout_height~"wrap content" Android:text-"Password:" /> <EditText Android:id="@* id/password" Android:layout width="fill parent" Android:layout height="wrap_content" Android:password-"true" Android:text="" /> </LinearLayouL>

in ttffl LincarLayout^lj/nj, Ji't'ttSE 3 (TextView)

*\W flirt til] r»A Name ill Password (Iffiil] f Android:password-"true" )

(EditText) Sif|-. Mfri^ tlwHj. 8-2 W^o ft»! 8-2 4»» iMJ"IW filJ, »»«AT«* EditView «ffilftA -^'f-ffi, ftfl m 8-3 Brie, illlRI 8-3 ffefflft Name X^fti^iJA IceskYsl, ft Password i^ti^'f1^ A Password, $

a m 8-3 Name *D Password a Ifl 8-4 ffl ill lit "J 'Al, rSMNHfAW Name fll Password. ft DBShared

Preferences.java 3tit111» jfctA'iWflftfi^iUl K0f'J<:

package us.imnet.iceskysl.db;

import: Android. app. Acti vi ty; import. Android, content. Sha redPreferences ; import Android.os.Bundle; import. Android. widget . EditText ;

public class DBSharedPreferences extends Activity {

public static final String SETTING_INFOS - "SETTING Infos";

public static final String NAME = "NAME";

public static final String PASSWORD = "PASSWORD";

private EditText field name; fttHft private EditText filed pass;

/** Cal.ed when the activity is first created. */ @Override public void onCreate(Bundle savedlnstanceState) I super.onCreate(savedlnstanceState); setContentView(R.layout.ma in); //Find View fieldname - (EditText) findViewByld(R.id.name); //tf 5t&IX ffl* A/fl/^fflM filed pass (EditText) findViewByld (R. id.password) ; // Restore preferences

SharedPreferences settings = getSharedPreferences (SETTING INFOS, 0); —^

SharedPreferences

String name - sett ir.gs . getString (NAME, ""); NAME

String password sett i ngs . get St ring ( PASSWORD, ""); PASSWORD

//Set value fieid_name.set.Text (name) ; field_name filed pass. setText (password) ; //^^hB^M^iH® T' filed pass

@Override protected void onStop()( super.onStop(); SharedPreferences settings SharedPreferences settings.edit ()

.putString(NAME, fieldname.getText().LoString()) .putString(PASSWORD, fiied_pass.getText() .toString ()) .commit();

\ //»ffl^fc*) mmftftik getSharedPreferences(SETTING INFOS, 0) ; // § 9c # — ^

# onCreate + findViewByld ftfiij Wt EditView in, tt'/tj getSharedPreferences SharedPreferences settings, M/fHiffl getString iR^K + ftfipWifi. JftJSttffl setText ^K-iftSWt EditText (MS.

HBftiSffisif onStop iitig, t&ttft&SfriliiHBi, ntcim getSharedPreferences flJPJ settings;

mm putString^«^ EditText + tik tnim commMo jirm^v

SharedPreferences # M » f. £ 7 ? * ■ ^n : SharedPreferences £ Ui XML ft#& &X# ft # A £ ###ft, £ DDMS + ft • File Explorer + & fl1 #J/data/data/<package name>/shared_prefs "f, Ui _h ffi &, ! SETTlNG_Infos.xml ftX#, iPffl8-5 0r*.

i/iMti/ircitffl/Hli/MjKiiirdriirerMutt. m> Irlipu Nilfott

(ll< t<>< W<< *«f«cltT lancit. r.,Vr\ tr.jitl he |id1k J^l,

Kii-

0 0

Post a comment