Android: PreferenceFragment shows only first preference

I am having problems downloading PreferenceFragmentin Android. This is really a basic implementation at the moment, which I want to expand later when it works.

The problem is that after going to SettingsFragmentonly the first preference is shown.

I am not getting any errors, but logcat shows me this:

W/PathParser: Points are too far apart 4.000000596046461

I was looking for this, but without any useful solutions.

The code is as follows:

MainActivity navigation through NavigationDrawer

navigate() is a common function using FragmentManager

case R.id.nav_settings:
    navigate(new SettingsFragment(), "settingsFragment", false);
    break;

SettingsFragment

public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
    public SettingsFragment() { }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public void onResume() {
        super.onResume();
        getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { }
}

prefences.xml

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

    <SwitchPreference
        android:key="switch_notifications"
        android:title="Notifications"
        android:summary="Receive notifications"
        android:defaultValue="true" >

    </SwitchPreference>

    <CheckBoxPreference
        android:key="switch_notifications2"
        android:title="Notifications"
        android:summary="Receive notifications"
        android:defaultValue="true" >

    </CheckBoxPreference>

</PreferenceScreen>

Screenshots

Left: actual output | Right: Preview

Actual output Preview

Thanks in advance!

Niels

+4
2

:

NestedScrollView, FrameLayout, android:fillViewport="true". , FrameLayout , wrap_content.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="nmct.jaspernielsmichielhein.watchfriends.view.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/frame_scrollview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" >

            <FrameLayout
                android:id="@+id/fragment_frame"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" >

            </FrameLayout>

        </android.support.v4.widget.NestedScrollView>

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>
+2

, ( ), . , , , (oneplus3), nexus 5, , .

: , - ? , paddingBottom , , .

, , , - , . , , , Android ..

+2

Source: https://habr.com/ru/post/1663878/


All Articles