Когда я создаю представление переработчика во вложенном представлении прокрутки, я не могу перейти к следующему действию, когда щелкаю элементы представления переработчика.
Не могли бы вы сказать мне, что делать?
Ниже мой код:
private fun setUpBookList(resultList : ArrayList<BookTranslate>){
bookList = resultList
if(bookList.isNotEmpty()){
val myAdapter = BookListAdapter(this.requireContext() , bookList )
myAdapter.notifyDataSetChanged()
myAdapter.onItemClick = { book ->
// do something with your item
val intent = Intent(this.requireActivity() , BookCoverActivity::class.java)
intent.putExtra("selectedBook" , book.id)
startActivity(intent)
}
val mLayoutManager = CustomLayoutManager(this.requireActivity(),
LinearLayoutManager.VERTICAL, false)
mLayoutManager.orientation = LinearLayoutManager.VERTICAL
recyclerview_book.layoutManager = mLayoutManager
(recyclerview_book.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
recyclerview_book.adapter = myAdapter
if(freeBook.id.isNullOrBlank()){
freeBook = bookList.first()
setUpTopBook(freeBook)
}
}
}
Adapter.kt
class BookListAdapter (internal val ctx : Context, internal var data: ArrayList<BookTranslate> ) : RecyclerView.Adapter<BookListAdapter.VHItem>() {
var onItemClick: ((BookTranslate) -> Unit)? = null
inner class VHItem(itemView: View) : RecyclerView.ViewHolder(itemView) {
var title: TextView? = null
var author: TextView? = null
init {
itemView.setOnClickListener {
onItemClick?.invoke(data[adapterPosition])
}
}
}
}
XML:
<LinearLayout
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"
android:layout_width="match_parent"
android:id="@+id/activity_main"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_book"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>