I have an login screen for my app. (spinner, edittext, button) and i want to store the spinner selected item and the inputted text to sharedpreferences. to use everywhere in the app.
code
Button lgnbutton;
EditText lgnfield;
Spinner lgnspinner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
lgnbutton = (Button) findViewById(R.id.loginbutton);
lgnfield = (EditText) findViewById(R.id.loginfield);
lgnspinner = (Spinner) findViewById(R.id.loginspinner);
lgnbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String ID = lgnfield.getText().toString();
String Type = lgnspinner.getSelectedItem().toString();
Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(myIntent);
}
});
}
}
Also it would be nice to skip the loginactivity and proceed to the mainactivity.
you can store login details and spinner selected item as in SharedPreferences
and in
onCreateofLoginActivitycheck if login details exist inSharedPreferencesif yes then move toMainActivityas :