0

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

为了直观地了解需要什么,类似这个屏幕的东西应该没问题:

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/AAAAAAAFiE/-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

任何帮助深表感谢。提前致谢

4

3 回答 3

2

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

另请查看线程以了解如何完成此操作。

于 2013-01-19T15:10:24.633 回答
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();
于 2013-01-19T15:10:54.597 回答
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()

             }
 }
于 2013-01-19T15:15:41.023 回答