Android Studio import the parameters of a data class into a xml file of another class

I create ItemValueVue.kt in java folder, I have that:

package en.first_project_test  import android.content.Context import android.util.AttributeSet import android.view.View import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import kotlinx.android.synthetic.main.view_item_value.view.*  class ItemValueView @JvmOverloads constructor(     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr) {      private val title: TextView     private val value: TextView     private val divider: View      init {         inflate(context, R.layout.view_item_value, this)          title = item_value_title         value = item_value_value         divider = item_value_divider          context.theme.obtainStyledAttributes(             attrs,             R.styleable.ItemValueView,             0, 0         ).apply {              try {                 title.text = getString(R.styleable.ItemValueView_title)                 value.text = getString(R.styleable.ItemValueView_value)                 divider.visibility = if (getInt(                         R.styleable.ItemValueView_dividerVisibility,                         0                     ) == 0                 ) View.VISIBLE else View.GONE             } finally {                 recycle()             }         }      } } 

In my Product.kt file, I have that:

package en.first_project_test  data class Product( val nom: String,                     val marque: String,                     val code_barres: String,                     val nutriscore : String,                     val novascore: Int,                     val Plat_vegetarien: Boolean,                     val Plat_vegetalien: Boolean,                     val url_image: String,                     val quantite: String,                     val listeVendu: Array<String>,                     val listeIngredients: Array<String>,                     val listeAllergènes: Array<String>,                     val listeAdditifs: Array<String> ){} 

In my test.xml file, I have that:

<?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">      <package en.first_project_test         android:id="@+id/textview_water"         android:layout_width="0dp"         android:layout_height="wrap_content"         app:dividerVisibility="visible"         app:title="Water"         app:nom="Dave"         app:layout_constraintTop_toBottomOf="@id/textview_ingredients"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintEnd_toEndOf="parent" />      </androidx.constraintlayout.widget.ConstraintLayout> 

My goal is to put the parameters of the Products class in the ItemValueVue tag but I can’t do it.

However, my app: title = "Water" works

I tried to make app: nom = "Dave" but it doesn’t work

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.