ошибка установки настраиваемого атрибута при привязке данных - Android - PullRequest
1 голос
/ 14 июля 2020
• 1000 1003 * "не может найти сеттер для" app: cpb_title ", который принимает тип параметра java .lang.String"

как это исправить?

attrs. xml

  <declare-styleable name="CircularProgressBar">
    <attr name="cpb_hasShadow" format="boolean"/>
    <attr name="cpb_progressColor" format="string"/>
    <attr name="cpb_backgroundColor" format="string"/>
    <attr name="cpb_title" format="string"/>
    <attr name="cpb_titleColor" format="string"/>
    <attr name="cpb_subtitle" format="string"/>
    <attr name="cpb_subtitleColor" format="string"/>
    <attr name="cpb_strokeWidth" format="integer"/>
</declare-styleable>

класс внутреннего вида

 String t = a.getString(R.styleable.CircularProgressBar_cpb_title);
    if(t!=null)
        mTitle = t;

1 Ответ

1 голос
/ 14 июля 2020

Вы можете использовать BindingAdapter вместо объявления атрибутов в файле attrs.xml. Выполните следующие действия:

class BindingUtil {

    @BindingAdapter("cpb_title")
    public static void setTitle(TextView view, String title) {
        view.setText(title);
    }
}

Затем вы можете использовать атрибут app:cpb_title в своем XML, как показано ниже:

               <Textview
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cpb_title="@{model.someStringField}" />
...