Android 中的组合首选项
我想要的自定义首选项看起来非常像开箱即用的 EditTextPreference ,只是它的行为就像一个“拆分按钮”,结合了两个首选项:如果用户单击左侧的文本,则会弹出编辑文本对话框;它允许用户设置首选项的“标签”;如果用户单击右侧的按钮,则会弹出另一个窗口,允许用户设置首选项的“日期”。
我想我可以扩展 EditTextPreference,但我不确定如何为单个首选项控件(或 Android 术语中的“小部件”)维护两个单独的键。或者是否可以“混合”两个首选项而无需子类化?
My desired custom preference looks very much like the out-of-box EditTextPreference, only that it behaves like a "split button" which combines two Preferences: if user clicks on the text on the left, the edit text dialog pops up; which allows user to set the "label" for the preference; if user clicks on the button on the right, another window pops up that allows user to set the "date" for the preference.
I guess I could extend EditTextPreference but I am not sure how I can maintain two separate keys for a single preference control (or "widget" in Android's term). Or is it possible to "mix up" two Preferences without subclassing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您不必使用内置的首选项小部件来管理您的首选项;例如,在我的应用程序中,我使用 PreferenceScreen 来打开带有自定义列表视图/适配器的多重选择对话框。如果您希望处理自己的键/值存储,可以使用 findPreference() 绑定到首选项,在 PreferenceActivity 的 onCreate() 中设置值,并将该值保留在活动的 onPause() 中。检查键/值首选项存储可以通过 getSharedPreferences(file,MODE.PRIVATE) 和关联的 getter 方法来完成。要编辑它们,请获取返回的 SharedPreferences 对象,并在进行更改后对其调用 edit() / commit() 。
这能回答你的问题吗?
Really you do not have to use the built in preference widgets to manage your preferences; for example, in my application, i use a PreferenceScreen to bring up a multiple selection dialog with a custom listview/adapter. If you wish to handle your own key/value store, you could bind to the preference with findPreference(), set the value in the PreferenceActivity's onCreate() and persist the value in the activity's onPause(). Examining the key / value preference store can be done via getSharedPreferences(file,MODE.PRIVATE) and an associated getter method. To edit them, take the SharedPreferences object that's returned and call edit() / commit() on it once changes have been made.
Does this answer you question?