• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Creating multi page preferences

Hello. I'm currently following this tutorial for trying to create a settings page using the preference library that will lead to another preference screen when a preference is selected. Basically I want my settings page to lead to another advanced settings page when a preference is selected.

What I currently have done is my settings fragment, my settings activity, the layout for my preferences and the layout for my settings activity.

activity_settings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SettingsActivity">


    <!--frame layout for displaying
        our preference fragment-->
    <FrameLayout
        android:id="@+id/idFrameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

SettingsActivity.java
Java:
package com.example.navapp;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import android.os.Bundle;


import android.os.Bundle;
import androidx.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;

public class SettingsActivity extends AppCompatActivity implements
        PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        // below line is to change
        // the title of our action bar.
        getSupportActionBar().setTitle("Settings");
        // below line is used to check if
        // frame layout is empty or not.
        if (findViewById(R.id.idFrameLayout) != null) {
            if (savedInstanceState != null) {
                return;
            }
            // below line is to inflate our fragment.
            getFragmentManager().beginTransaction().add(R.id.idFrameLayout, new SettingsFragment()).commit();
            PreferenceManager.

        }
    }

    @Override
    public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
        final Bundle args = pref.getExtras();
        final Fragment fragment = this.getSupportFragmentManager().getFragmentFactory().instantiate(
                this.getClassLoader(),
        fragment.setArguments(args);
        fragment.setTargetFragment(caller, 0);

        int setupSettingsFragment = getFragmentManager().findFragmentByTag("FeedbackFragment").getId();

        this.getSupportFragmentManager().beginTransaction()
                .replace(setupSettingsFragment, fragment)
                .addToBackStack(null)
                .commit();

        return true;
    }


}

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


    <SwitchPreference
        android:key="switch"
        android:summaryOff="Switch off"
        android:summaryOn="Switch on"
        android:title="Switch Preference"
        android:fragment="com.example.navapp.FeedbackFragment"/>

    <Preference
        android:key="feedback"
        android:title="Send feedback"
        android:summary="Report technical issues or suggest new features"/>
        android:fragment="com.example.navapp.FeedbackFragment"/>


</PreferenceScreen>

SettingsFragment.java
Java:
package com.example.navapp;
import android.os.Bundle;
import android.preference.PreferenceFragment;

import androidx.annotation.Nullable;

public class SettingsFragment extends PreferenceFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // below line is used to add preference
        // fragment from our xml folder.
        addPreferencesFromResource(R.xml.preferences);
    }
}

feedback.xml


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

    <Preference
        android:key="feedback"
        android:title="Send feedback to devs"
        android:summary="Report technical issues or suggest new features"/>

</PreferenceScreen>

FeedbackFragment.java

Java:
package com.example.navapp;
import android.os.Bundle;
import android.preference.PreferenceFragment;

import androidx.annotation.Nullable;

public class FeedbackFragment extends PreferenceFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // below line is used to add preference
        // fragment from our xml folder.
        addPreferencesFromResource(R.xml.feedback);
    }
}



I'm trying to use the onPreferenceStartFragment method to replace the layout with my new fragment. However, I'm currently struggling with figuring out how to attach a preference to this listener and how this code works.

This is my first post in this forum so any feedback on how I can improve my posts would also be great.

Help No text and email notification sounds

Recently notification sounds for new email and text messages have stopped. I notice only a short vibration for text and nothing for email. Sound works fine elsewhere. For instance the ring tone works and can be changed without a problem. Facebook notifications also have sound. I use Messages+ for text and I've gone into the settings to confirm that there's a sound associated with receipt of new messages. I've also changed the sound, but it doesn't work. The phone has Android v10 and is up to date on the Verizon network. All apps are up to date in Google Play. Any help with this will be appreciated

Audio Crackling over Bluetooth

About a month later and a few road trips done and I've narrowed it down to my State Farm beacon being the cause. I also found out the tweeters in my car are outright trash as is, but at least the crackling stopped. Every time the beacon detects movement it connects to my phone and the audio quality of my music dies with it causing bass to become muffled and high frequency notes to choke on themselves. I guess the phone can't handle being connected to two Bluetooth things at once?

No, it is just RF (radio frewuency) interference.

I thought something else when reading this thread, until you found the actual culprit.

Believe it or not, the very same thing happened to me even through a wired connection (headphone jack to input of portable stereo).

Turns out it was interference wheneer the phone pinged off the tower, which was too distant to get a decent signal- so the phone ramps up the RF power to make that connection- and voila!
horrible sounds over the radio.

Help Want to Disable Last Number Redial

Instead of turning bluetooth off by going into phone settings, use the bluetooth icon in Quick Settings.

Pull down the quick settings menu and tap the icon to disconnect, and also to connect.

If the icon is not present in the quick settings, then open quick settings, enter the edit mode, and add it.

TIP:
The top 5-6 icons in the list are the ones that show first and are the ones that appear when you only pull down the control panel.

These should be set to be the ones you use the most, and in this case, you probably want Bluetooth to be one of them.

Ip through usb

hey,
i will be more clear, the devices i tested it's not exectly router, it's kind of device that can give ip by connecting him (dhcp or static)
1.i have two cables that suitable to the device one with ethernet conector and one with usb my goal it's to be able to connect two devices to the s10+ and get opttion to use them both with differnt ip.
when im connecting the ethernet cable i recive ip when im using the usb not, i can see the interface when im use ip command on teminal (usb0). i tried to connect the usb connector to directly to the s10 but it didnt help.

Filter

Back
Top Bottom