Android-привязка: вызов метода просмотра в xml
Android Studio 3.1.2
Я хочу зачеркнуть текст в текстовом представлении. Поэтому я использую этот подход:
Здесь xml:
<layout 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">
<data>
<import type="android.view.View" />
<variable
name="handler"
type="myproject.MyHandler" />
<variable
name="item"
type="myproject.Product" />
</data>
<TextView
android:id="@+id/priceWithoutDiscountTextView"
style="@style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/price"
android:textColor="@color/color_primary"
app:strike_price="@{item.price}" />
</android.support.constraint.ConstraintLayout>
</layout>
Here code in recycler view adapter:
@BindingAdapter("strike_price")
public static void setPrice(TextView view, float price) {
view.setPaintFlags(view.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
В результате цена является страйком. Ницца. Это отлично работает. Но я хочу вызвать метод
view.setPaintFlags(view.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
прямо в XML. Является ли это возможным?