如何解决我无法使用数据绑定在属性值上设置 int
attrs.xml
<declare-styleable name="CounterView">
<attr name="count" format="integer" />
CounterView
class CounterView(context: Context,attrs: AttributeSet?) : LinearLayout(context,attrs) {
var mCountAddListener: () -> Unit = {}
var mCountRemoveListener: () -> Unit = {}
init {
val attributes = context.obtainStyledAttributes(
attrs,R.styleable.CounterView,0
)
val count = attributes.getInt(R.styleable.CounterView_count,0)
attributes.recycle()
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
inflater.inflate(R.layout.view_counter,this,true)
orientation = HORIZONTAL
gravity = Gravity.CENTER_VERTICAL
weightSum = 3f
setPadding(resources.getDimensionPixelSize(R.dimen.minimum_margin_vertical))
(getChildAt(1) as MaterialTextView).text = count.toString()
(getChildAt(0) as ImageView).setOnClickListener { mCountRemoveListener() }
(getChildAt(2) as ImageView).setOnClickListener { mCountAddListener() }
}
fun updateCountAddListener(countAddListener: () -> Unit) {
mCountAddListener = countAddListener
}
fun updateCountRemoveListener(countRemoveListener: () -> Unit) {
mCountRemoveListener = countRemoveListener
}
}
item_movie_view.xml
<variable
name="movie"
type="example.package.domain.model.Movie" />
<example.package.view.CounterView
android:id="@+id/counterView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:count="@{movie.countOnCart}" />
这是错误消息:找不到接受参数类型“int”的
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。