如何以编程方式修改 CheckBoxPreference 视图
如何在运行时更改 CheckBoxPreference 的视图?
具体来说,我想根据用户是否选中该框来更改 CheckBoxPreference 摘要。
如果它是一个普通的视图,我可以这样做:
view1 = (TextView)findViewById(R.id.idView1);
view1.setText("some text");
但是 CheckBoxPreference 没有 id,所以我不知道如何获取它的“句柄”。
How can I change the view of a CheckBoxPreference at runtime?
Specifically, I'd like to change a CheckBoxPreference summary depending on whether the user has checked the box or not.
If it were a normal view, I could do something like:
view1 = (TextView)findViewById(R.id.idView1);
view1.setText("some text");
But a CheckBoxPreference has no id, so I don't know how to get a "handle" to it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对自己的问题有一个答案。关键是在
PreferenceActivity
中使用findPreference
,如下所示:这已经过测试并且有效。
I have an answer to my own question. The key is to use
findPreference
in aPreferenceActivity
, as follows:This is tested and works.
您应该使用(在 XML 布局文件中):
You should use (in XML layout file):
您可以使用 xml 中的
android:id
将 id 设置为 CheckBoxPreference,如下面的代码要检索您可以使用
You can set id to CheckBoxPreference using
android:id
in xml like code belowTo retrieve you can use