ashish
ashish

Reputation: 1

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.

Upvotes: 0

Views: 117

Answers (1)

syam
syam

Reputation: 445

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();
    }
    }

Upvotes: 1

Related Questions