【问题标题】:Android save details screenAndroid 保存详细信息屏幕
【发布时间】:2013-01-19 23:15:41
【问题描述】:

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

为了直观地了解所需的内容,类似这个屏幕应该没问题:

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

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

【问题讨论】:

    标签: java android android-layout


    【解决方案1】:

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

    还请查看this 线程以了解如何做到这一点。

    【讨论】:

      【解决方案2】:

      使用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();
      

      【讨论】:

        【解决方案3】:

        你可以在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()
        
                     }
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-24
          • 1970-01-01
          • 1970-01-01
          • 2018-12-08
          • 2020-10-15
          • 2019-08-24
          相关资源
          最近更新 更多