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();
}
}
精彩评论