Reputation: 33
I made this app which the user inputs the school name, and it will link to the website. So, I want to know how to save the school name, so you don't have to put it in every time you open the app. Thank you.
My app contains an edittext, a go button (Which I want to use it as a save also), and a webview.
Upvotes: 0
Views: 1078
Reputation: 319
you can save the value using something like this:
final EditText eActNametwo = (EditText)findViewById(R.id.eACTNametwo);
final EditText eActBudtwo = (EditText)findViewById(R.id.eACTBudtwo);
bCreatetwo = (Button)findViewById(R.id.bCreateActivitytwo);
bCreatetwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SharedPreferences settingstwo = getSharedPreferences(actnamefiletwo,0);
SharedPreferences.Editor editortwo = settingstwo.edit();
editortwo.putString("nametwo", eActNametwo.getText().toString());
editortwo.putString("budtwo", eActBudtwo.getText().toString());
editortwo.commit();
}
});
and then u call the value somewhere using this
entvActNametwo = (TextView) findViewById(R.id.tvActNametwo);
tvActBudtwo = (TextView) findViewById(R.id.tvActBudtwo);
SharedPreferences settingstwo = getSharedPreferences(actnamefiletwo, 0);
tvActNametwo.setText(settingstwo.getString("nametwo", ""));
tvActBudtwo.setText(settingstwo.getString("budtwo", ""));
you will need to call your string prior to onCreate like this:
public static final String actnamefiletwo = "actnamebudtwo";
This is an example from my own app, hope it helps
Upvotes: 0
Reputation: 876
I recommend you looking at http://developer.android.com/training/basics/data-storage/index.html For this particular point where's there is only one string to store, I'd use the SharedPreference You'll find what you need on the training guide ;)
Upvotes: 1