'How to transfer the radioButton value to preferences screen

How to transfer the radioButton value obtained from the activity and insert this value into preferences (settings screen) Please help me. enter image description here

Insert settings here enter image description here

ChooseGender.class I try do this, but its not workable

        class ChooseGender: AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.choose_gender)
        applySetting()
    }
private fun applySetting() {
    val sharedPref: SharedPreferences = getSharedPreferences("mypref", Context.MODE_PRIVATE)
    radioMale.setOnClickListener {
        sharedPref.getInt("GENDER",1)
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
    }
    radioFemale.setOnClickListener {
        sharedPref.getInt("GENDER",2)
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
    }
}

}

Preferences.xml

<PreferenceCategory
        android:title="@string/preferenceTitle2">

        <ListPreference
            android:key="GENDER"
            android:title="@string/gender"
            android:summary="%s"
            android:defaultValue="1"
            android:entries="@array/gender_entries"
            android:entryValues="@array/gender_entries_values"/>
    </PreferenceCategory>

Array preference

<resources>
    <string-array name="gender_entries">
        <item>@string/man</item>
        <item>@string/women</item>
    </string-array>
    <string-array name="gender_entries_values">
        <item>1</item>
        <item>2</item>
    </string-array>
</resources>

choose_gender.xml <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">

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView12">

        <RadioButton
            android:id="@+id/radioMale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/man"
            android:textSize="20sp"/>


        <RadioButton
            android:id="@+id/radioFemale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/women"
            android:textSize="20sp"/>
    </RadioGroup>

</androidx.constraintlayout.widget.ConstraintLayout>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source