Android保存详细信息屏幕

时间:2013-01-19 15:04:52

标签: java android android-layout

我正在开发一个小项目,需要一个详细信息屏幕,用户输入他的详细信息并永久存储。如果用户需要,用户还必须可以选择更改详细信息。我查看了保存的首选项库,但它似乎没有提供这样的功能。

为了直观地了解需要什么,像这个屏幕应该没问题:

http://www.google.com.mt/imgres?start=97&num=10&hl=en&tbo=d&biw=1366&bih=643&tbm=isch&tbnid=aQSZz782gIfOeM:&imgrefurl=http://andrejusb.blogspot.com/2011/10/iphone-web-application-development-with.html&docid=YpPF3-T8zLGOAM&imgurl=http://2.bp.blogspot.com/-YRISJXXajD0/Tq2KTpcqWiI/AAAAAAAAFiE/-aJen8IuVRM/s1600/7.png&w=365&h=712&ei=rbX6ULTDCOfV4gTroIDoCg&zoom=1&iact=hc&vpx=834&vpy=218&dur=2075&hovh=314&hovw=161&tx=80&ty=216&sig=108811856681773622351&page=4&tbnh=155&tbnw=79&ndsp=35&ved=1t:429,r:4,s:100,i:16

非常感谢任何帮助。提前致谢

3 个答案:

答案 0 :(得分:2)

您可以轻松使用Shared Preferences来存储用户的详细信息。每次打开“首选项”屏幕时,都可以从“共享首选项”中提取存储的数据,并将其呈现给用户进行编辑。编辑完成后,新数据可以在共享首选项中更新回来。

另请查看this帖子,看看如何做到这一点。

答案 1 :(得分:1)

使用SharedPreferences对于您希望持久存储的这类少量数据非常适合。

// 'this' is simply your Application Context, so you can access this nearly anywhere
SharedPreferences prefs = this.getSharedPreferences(
  "com.example.app", Context.MODE_PRIVATE);

从偏好中获取:

// You can equally use KEY_LAST_NAME to get the last name, etc. They are just key/value pairs
// Note that the 2nd arg is simply the default value if there is no key/value mapping
String firstName = prefs.getString(KEY_FIRST_NAME_CONSTANT, "");

或保存:

Editor editor = prefs.edit();
// firstName being the text they entered in the EditText
editor.putString(KEY_FIRST_NAME_CONSTANT, firstName);
editor.commit();

答案 2 :(得分:1)

您可以使用android中的SharedPreferences类来实现此类功能。

public void onCreate(Bundle object){
             super.onCreate(object);
             // Initialize UI and link xml data to java view objects
              ......
              SharedPreferences myPref = getPreferences(MODE_PRIVATE);
              nameView.setText(myPref.getString("USER_NAME", null));
              passView.setText(myPref.getString("PASSWORD", null));

      }
public void onStop(){
             super.onStop();
             if (isFinishing()) {

             getPreferences(MODE_PRIVATE).edit()
             .putString("USER_NAME", nameView.getText().toString())
             .putString("PASSWORD",  passView.getText().toString())
             .commit()

             }
 }