有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在PreferenceActivity中膨胀视图?当听众不工作时

我有一个首选xml文件:

<?xml version="1.0" encoding="utf-8"?>

<com.example.checkboxtest.MyCheckBox 安卓:title="Preference 1" 安卓:key="alert"
安卓:widgetLayout="@layout/preference_checkbox"/>

然后我的布局-首选项复选框

  <LinearLayout 安卓:layout_width="wrap_content" 安卓:layout_height="wrap_content" 安卓:id="@+id/ax" xmlns:安卓="http://schemas.安卓.com/apk/res/安卓">

<com.example.checkboxtest.MyChckBox 
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:button="@drawable/checkbox"
    安卓:clickable="true"
    安卓: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");

        }
    }); 

问题是onclicklistener从未被触发,即使我夸大了布局。怎么了

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

onclick not working for inflated layout Inflated layout's buttons onClick listener not working


共 (0) 个答案