【问题标题】:ListPreference not showing by clicking on preference screen通过单击首选项屏幕未显示 ListPreference
【发布时间】:2014-11-17 16:08:21
【问题描述】:

当我在 Preference 屏幕上单击 ListPreference 时没有任何反应。 没有显示可供选择的条目。 (我在 Android 4.4 上测试)

偏好xml:

<PreferenceCategory
        android:title="Image"
        android:key="image">
    <ListPreference
                android:title="Flash"
                android:key="flash"
                android:defaultValue="Off"
                android:entries="@array/flash"
                android:entryValues="@array/flash_values"
                android:persistent="true"/>
    </PreferenceCategory>

数组值 xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="opts">
        <item>auto</item>
        <item>50</item>
        <item>100</item>
        <item>200</item>
        <item>400</item>
        <item>800</item>
    </string-array>

    <string-array name="opts_values">
        <item>auto</item>
        <item>50</item>
        <item>100</item>
        <item>200</item>
        <item>400</item>
        <item>800</item>
    </string-array>

    <string-array name="flash">
        <item>Auto</item>
        <item>On</item>
        <item>Off</item>
    </string-array>

    <string-array name="flash_values">
        <item>0</item>
        <item>1</item>
        <item>2</item>
    </string-array>
</resources>

标题已正确显示,但单击首选项时没有任何反应。构建时没有错误。 首选项列表不显示为对话框。所有其他类型都正常工作。

编辑:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="prefscr">

    <PreferenceCategory
        android:title="Image"
        android:key="image">

        <SwitchPreference
            android:title="Video Mode"
            android:key="video"
            android:defaultValue="false"/>

        <ListPreference
            android:title="Flash"
            android:key="flash"
            android:defaultValue="Off"
            android:entries="@array/flash"
            android:entryValues="@array/flash_values"
            android:persistent="true"/>

        <SwitchPreference
            android:title="PNG"
            android:key="png"
            android:defaultValue="false"
            android:summary="Image format in PNG"
            android:enabled="false"/>

        <ListPreference
            android:title="Iso"
            android:key="iso"
            android:summary="set iso value"
            android:entries="@array/opts"
            android:entryValues="@array/opts_values"
            android:enabled="true"
            android:persistent="true"
            android:defaultValue="auto"/>

        </PreferenceCategory>

</PreferenceScreen>

【问题讨论】:

  • 我将您的数组和 ListPreference 添加到了一个测试项目中,并且它有效。您的偏好活动中是否有任何相关代码?

标签: android xml android-4.4-kitkat listpreference


【解决方案1】:

根据我的评论 - 检查您的偏好活动,以确保您没有任何可能覆盖默认行为的代码(即,在您的偏好上有一个触摸监听器正在窃取触摸事件)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    相关资源
    最近更新 更多