Java 在PreferenceActivity中膨胀视图?onclick侦听器不工作

Java 在PreferenceActivity中膨胀视图?onclick侦听器不工作,java,android,preferenceactivity,Java,Android,Preferenceactivity,我有一个首选项xml文件: <?xml version="1.0" encoding="utf-8"?> 问题是onclicklistener从未被触发,即使我夸大了布局。有什么不对劲吗 此外,我在这里检查了一些类似的主题,但找不到正确的答案: 改用CompoundButton.OnCheckedChangeListener。我知道。但既然CheckBox是一个按钮,那么它也应该和OnClickListeners一起工作。好吧,看看你能不能说服它更像按钮。 <com.exa

我有一个首选项xml文件:

<?xml version="1.0" encoding="utf-8"?>
问题是onclicklistener从未被触发,即使我夸大了布局。有什么不对劲吗

此外,我在这里检查了一些类似的主题,但找不到正确的答案:


改用CompoundButton.OnCheckedChangeListener。我知道。但既然CheckBox是一个按钮,那么它也应该和OnClickListeners一起工作。好吧,看看你能不能说服它更像按钮。
<com.example.checkboxtest.MyCheckBox android:title="Preference 1" android:key="alert"
android:widgetLayout="@layout/preference_checkbox"/>
  <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ax" xmlns:android="http://schemas.android.com/apk/res/android">

<com.example.checkboxtest.MyChckBox 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/checkbox"
    android:clickable="true"
    android:id="@+id/alerttt"

/>
</LinearLayout>
MyCheckBox cb = (MyCheckBox) findPreference("alert");


    LayoutInflater lif = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);



View v = lif.inflate(R.layout.preference_checkbox, null);

MyChckBox c = (MyChckBox) v.findViewById(R.id.alerttt);

    c.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Log.d("DEBUG", "clicked");

        }
    });