巴顿在preference文件 [英] Button in preference file

查看:114
本文介绍了巴顿在preference文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置在preference.xml文件中的两个按钮。我想去的主要活动,当我点击确定按钮。在这样的情况code是在哪里写的?

I have set the two buttons in preference.xml file. I want to go to main activity when I click the "ok" button. So for that code is where to write?

推荐答案

您可以设置在preferenceClickListener在preferenceActivity。

You can set an onPreferenceClickListener in your PreferenceActivity.

在preference的xml:

in preference xml :

<Preference android:title="Preference Button" android:summary="This works almost like a button" android:key="mypref" />

在preferences活动:

in preferences activity :

public class Preferences extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
            // Get the custom preference
            Preference mypref = (Preference) findPreference("mypref");
            mypref.setOnPreferenceClickListener(new OnPreferenceClickListener() { });
}
}

这篇关于巴顿在preference文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆