安卓preferences onclick事件 [英] Android preferences onclick event
本文介绍了安卓preferences onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的preferences.xml我有这样的preference元素:
In my preferences.xml I have a preference element like this:
<Preference android:title="About" />
我要分配的onClick
事件,因此,如果用户将点击它,我就可以做开放新的意图
或浏览器。我试图做到这一点像我这样做的按钮,但是这似乎并没有工作。
I want to assign onClick
event, so if user would click on it, I would be able to do open new Intent
or browser. I tried to do it like I do with buttons, but this not seem to work.
推荐答案
巴德尔
您需要设置安卓键
的项目,然后在你的code,你可以做...
You need to set android:key
for the item, Then in your code you can do...
假设你使用的XML如下:
Assuming you use the following in your XML:
<Preference android:title="About" android:key="myKey"></Preference>
然后,你可以做你的code以下内容:
Then you can do the following in your code:
Preference myPref = (Preference) findPreference("myKey");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
//open browser or intent here
}
});
这篇关于安卓preferences onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文