Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Pass another view as parameter in data binding

I am trying to pass a another view of my xml as a parameter of a method in Google data binding... like this:

<LinearLayout
    android:id="@+id/faq_subject_about_ego"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/border_faq_btn"
    android:orientation="horizontal"
    android:layout_marginBottom="20dp"
    android:padding="4dp"
    android:gravity="center"
    android:onClick='@{(faq_title_about) -> viewModel.subjectRequest(faq_title_about.getText())}'>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon_faq"
        android:layout_marginRight="8dp"
        android:clickable="false" />

    <ebanx.com.ego.utils.custom_extension.CustomButtonBold
        android:id="@+id/faq_title_about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Button_FAQ"
        android:text="@string/btn_about_ego"
        android:clickable="false" />
</LinearLayout>

I need the text that is in my CustomButtonBold... But this is not working.

How can I pass the text of the button as a parameter?

Any help is appreciated!

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The member generated for the id-able has a CamelCase name format. Also the view provided to the OnClickListener is the view being clicked. So just name the parameter arbitrarily and use the correct "global" member.

android:onClick='@{(v) -> viewModel.subjectRequest(faqTitleAbout.getText())}'
about 4 years ago · Santiago Trujillo Denunciar

0

If you are coding in Kotlin you could be tempted to write the following:

android:onClick='@{(v) -> viewModel.subjectRequest(faqTitleAbout.text)}'

It won't work, because the binding class is generated by the framework in Java. Another problem is that with EditText views you need to add also a call to

toString()

If you want to call a function that takes a string as parameter. So the code would be:

android:onClick='@{(v) -> viewModel.subjectRequest(faqTitleAbout.getText().toString())}'

That's how it works with Kotlin and Android Studio 4.1.2, otherwise you get a build error (...a weird one...). I don't know if that will change in the future or it has a different behavior with other versions.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda