0

I need to create activity for preferences and place some Views at bottom(under preferences). I have created layout, but only first category label is visible. Why switch is invisible? Here is what i have:

  • 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>        
    
Zufar Muhamadeev
  • 3,085
  • 5
  • 23
  • 51

1 Answers1

0

I found problem. Preference fragment is in scrollable list itself, so to achive desired behaviour i have implemented custom preference. Here is example of custom preference layout(without preference extension).

I also have requirement to add click listeners. To implement it i have extended Preference class and added listeners in onCreateView method. Here is example of extending preference.

Zufar Muhamadeev
  • 3,085
  • 5
  • 23
  • 51