I have a layout which contains an edittext and two button for increment and decrement of the value in editext. Now I am using include
to use this button in my activity
as I am having multiple use of that.
eg :-
<include
android:id="@+id/editTextOne"
layout="@layout/include_edittext_with_buttons"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<include
android:id="@+id/editTextTwo"
layout="@layout/include_edittext_with_buttons"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
I can get the onClick
events of my increment
and decrement
buttons but I don't understand how will i catch that the onClick
of the particular include
has been clicked. ?
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText"
android:layout_width="@dimen/_120sdp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/btnPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/_10sdp"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="@id/editText"
app:layout_constraintEnd_toEndOf="@id/editText"
app:layout_constraintTop_toTopOf="@id/editText" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/btnMinus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_10sdp"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="@id/editText"
app:layout_constraintStart_toStartOf="@id/editText"
app:layout_constraintTop_toTopOf="@id/editText" />
</androidx.constraintlayout.widget.ConstraintLayout>
NOTE :- I get that working using binding. editTextOne.btnPlus.setOnClickListener { Toast.makeText(this, "Plus", Toast.LENGTH_SHORT).show() }
and similar for the other's but what i want is I can write the plus
and minus
click listener once and then they update the values of the edittext
in which they are included only.
Not sure if that would be possible any better suggestions ?