将自定义值保存到android中的首选项?
我有一个首选项设置,我使用下面的代码配置了一个在单击首选项时弹出的对话框。
Dialog passwordDialog = new Dialog(this);
passwordDialog.setContentView(R.layout.password_dialog);
passwordDialog.setTitle("Set new password.");
passwordDialog.setCancelable(true);
passwordDialog.show();
对话进展顺利。但是,在对话框中我有一个密码编辑文本和一个确认密码编辑文本。如果这些相互匹配,我需要将密码保存到首选项。我不知道如何在自定义对话框中单击“确定”时将值保存到首选项中。请让我知道如何执行此操作。感谢您的时间和帮助。
I have a preference settings for which i have configured a dialog box pop up on click of preference using the below code.
Dialog passwordDialog = new Dialog(this);
passwordDialog.setContentView(R.layout.password_dialog);
passwordDialog.setTitle("Set new password.");
passwordDialog.setCancelable(true);
passwordDialog.show();
The dialog is coming fine. However In the dialog i have a password edit text and a confirm password edit text. If these matches with each other i need to save the password to preference. I do not know how to save the value to a preference on ok click in my custom dialog. Please let me know how to do this. Thank you for your time and help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检索首选项,然后向其中提交信息:
要将信息添加到首选项,请首先调用 edit() (返回编辑器),添加所需的值(键/值,如地图),并且永远不会忘记调用 commit() (提交更改)。
然后您可以使用以下方式访问您的值
You can retrieve the preferences, and then commit information to it :
To add information to a preference, start by calling edit() (returns an editor), add the value you want (key/value, like a Map), and never forget to call commit() (to commit the changes).
You can then access your value using