I have a custom layout which has a textview and ratingbar , and then i set the layout as view to my preferences , the problem is that i tried to inflate the view in my preferences fragment and set the ratingbar onclick , i put a log to see if it is clicked or not but nothing is happening
- This is my preference
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:title="@string/YourPreferredLanguage"
android:icon="@drawable/ic_baseline_language_24" />
<CheckBoxPreference
android:title="@string/french"
android:key="french"
/>
<CheckBoxPreference
android:title="@string/portuguese"
android:key="portuguese"
/>
<Preference
android:title="Rate Our App"
android:icon="@drawable/ic_baseline_stars_24"
/>
<PreferenceCategory
android:layout="@layout/ratinglayout"/> //this is my custom layout
</PreferenceScreen>
- This is my layout
<?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="wrap_content">
<TextView
android:id="@+id/ratingtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="75dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="20dp"
android:text="Rate "
android:textColor="@android:color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:numStars="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.75"
app:layout_constraintStart_toEndOf="@+id/ratingtext"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
*Snippet of code of how i m implementing it
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.settingspreferences,rootKey)
val view = LayoutInflater.from(requireContext()).inflate(R.layout.ratinglayout,null,false)
val ratingbars = view.findViewById<RatingBar>(R.id.ratingBar)
ratingbars.setOnRatingBarChangeListener { ratingBar, rating, fromUser ->
Log.d("TAG","Rating is " + rating) // when i click on rating bar , nothing happens
}
}
Any help would be appreciated guys , thank you .