如何保存TextView的价值观共享preferences [英] How to save TextView Values in SharedPreferences
本文介绍了如何保存TextView的价值观共享preferences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何保存TextView的价值观共享preferences,见下面我的code,让我知道如何存储到共享preferences和检索的onCreate(..)
How to save TextView values in SharedPreferences, see my code below and let me know how to store to SharedPreferences and retrieve in onCreate(..)
我的code是这样的:
my code looks like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
txtOperative = (TextView) findViewById(R.id.currentOperative);
txtEvent = (TextView) findViewById(R.id.currentEvent);
intent = getIntent();
strEventName = intent.getStringExtra("eventName");
strOperativeName = intent.getStringExtra("operativeName");
txtEvent.setText(strEventName);
txtOperative.setText(strOperativeName);
}
我想在TextViews,每当用户回来到这个活动始终显示这些值
推荐答案
可以方便地使用这种对于保存在共享preference你的TextView值
Simple use this for save your TextView value in sharedpreference
SharedPreferences sp = getSharedPreferences("key", 0);
SharedPreferences.Editor sedt = sp.edit();
sedt.putString("textvalue", txtEvent.getText().toString());
sedt.putString("txtopertaive", txtOperative.getText().toString());
sedt.commit();
现在以后找回随时随地在你的Activity类或任何其它活动由
Now after that retrieve it anywhere in your Activity class or any other Activity by
SharedPreferences sp = getSharedPreferences("key", 0);
String tValue = sp.getString("textvalue","");
String tOperative = sp.getString("txtopertaive","");
这篇关于如何保存TextView的价值观共享preferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文