2017-11-02 7 views
0

プリファレンスのアクティビティーを作成し、いくつかのビューを(プリファレンスの下に)下部に配置する必要があります。レイアウトを作成しましたが、最初のカテゴリラベルだけが表示されます。スイッチが見えないのはなぜですか?ここで私が持っているものです。アクティビティーの一部としてのプリファレンスフラグメント

  • activity_layout.xml:

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
           android:orientation="vertical" 
           android:layout_width="match_parent" 
           android:layout_height="match_parent"> 
        <ScrollView 
         android:id="@+id/settingsForm" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 
         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:orientation="vertical"> 
          <fragment 
           android:id="@+id/settingsFragment" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           class="com.example.SettingsFragment"/> 
          <LinearLayout 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:orientation="vertical"> 
           <!-- views --> 
          </LinearLayout> 
         </LinearLayout> 
        </ScrollView> 
    </LinearLayout> 
    
  • SettingsFragment exends PreferenceFragment:

     public void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState); 
          addPreferencesFromResource(R.xml.preferences); 
          //... 
         } 
    
  • あるpreferences.xml

    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
        <PreferenceCategory 
         android:title="@string/pref_work_storage_title" 
         android:key="pref_work_category"> 
         <SwitchPreference 
          android:key="pref_work_unavailable" 
          android:defaultValue="true" 
          android:summaryOn="@string/pref_work_available" 
          android:summaryOff="@string/pref_work_unavailable"/> 
        </PreferenceCategory> 
    </PreferenceScreen>   
    

答えて

0

問題が見つかりました。 Preferenceフラグメントはスクロール可能なリスト自体にあります。したがって、希望の動作を実現するために、私はカスタム設定を実装しました。ここには、カスタムプリファレンスレイアウトのexampleがあります(プリファレンス拡張なし)。

また、クリックリスナーを追加する必要があります。それを実装するには、Preferenceクラスを拡張し、onCreateViewメソッドでリスナーを追加しました。拡張優先のexampleがあります。

関連する問題