开发者

Using Shared preferences

show example when user fill the phone number and password in edit text and click submit开发者_开发百科 this information stored in a database using shared preferences.


Shared preferences get stored in the file and not in the database.

SharedPreferences myPrefs;
    myPrefs = this.getSharedPreferences("preference", MODE_PRIVATE);
    EditText phonenumber_edit = (EditText) findViewById(R.id.phonenumber_edit);
    EditText password_edit = (EditText) findViewById(R.id.password_edit);
    Button submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
    SharedPreferences.Editor prefsEditor = myPrefs.edit();
    prefsEditor.putString("phonenumber", phonenumber_edit.getText());
    prefsEditor.putString("password", password_edit.getText());
    prefsEditor.commit();
    }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜