0

I am seeking forgiveness for this simple problem. I am using FastAdapter for the first time and I am new to Kotlin. Let me share the problem. I have a layout for the recyclerview item holder, an adapter which extends AbstractItem class.

Actually I couldn't format the code correctly here on Stack overflow. So I created the code at GitHub Gist. Here is the link.

In the layout_add_item.xml file, I have two buttons, one's id is addStudent and another one's id is addTeacher.

So, my problem is, these two button's onClickListener is not triggered until I click on the root layout once on every onCreate method is called. If I click on the LinearLayout once, then these two button's onClickEvent get fired normally.

I don't know what's wrong here :-(

Any help would be appreciated. Thanks in advance.

4

1 回答 1

0

EventHook中公开的系统背后的概念FastAdapter旨在确保每次数据绑定到项目时不会松散地重新连接侦听器,或者更糟糕的是引入内存泄漏。

因此,API 本身试图阻止这些各个方面。

使用 KotlinFastAdapter公开了一种方法,可以为您进一步简化此设置过程。

例如:

mFastAdapter.addClickListener({ vh: SimpleImageItem.ViewHolder -> vh.imageView }) { view, position, fastAdapter, item ->
   // react on the click on the `imageView` of the `SimpleImageItem.ViewHolder`            
}
于 2021-02-05T10:05:56.937 回答