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.

Raza
  • 791
  • 7
  • 22
kaunj2020
  • 51
  • 8

1 Answers1

0

The concept behind the EventHook system exposed in the FastAdapter is meant to ensure listeners are not loosely re-attached everytime the data gets bound to the item, or even worse to introduce memory leaks.

The API itself due to that tries to prevent those various aspects.

Using Kotlin the FastAdapter exposes a method which should simplify this setup procedure some more for you.

For example:

mFastAdapter.addClickListener({ vh: SimpleImageItem.ViewHolder -> vh.imageView }) { view, position, fastAdapter, item ->
   // react on the click on the `imageView` of the `SimpleImageItem.ViewHolder`            
}
mikepenz
  • 12,708
  • 14
  • 77
  • 117