Recyclerview
shows all the items, but I can't scroll it. Also in a way that I can't understand, once I click and open the searchView
, I'm able to scroll just a bit (still not fully). How can I get the recyclerview
to scroll?
Here is the Constraint Layout that includes Recycler View
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="@dimen/_10sdp"
android:paddingTop="@dimen/_10sdp"
android:text="@string/notes"
android:textColor="@color/ColorWhite"
android:textSize="@dimen/_15sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<SearchView
android:queryHint="@string/search"
android:theme="@style/ThemeOverlay.search"
android:iconifiedByDefault="false"
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_10sdp"
android:background="@drawable/background"
android:searchIcon="@drawable/ic_search"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv1" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:nestedScrollingEnabled="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_10sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:overScrollMode="never"
app:layout_constraintTop_toBottomOf="@id/search_view" />
<LinearLayout
android:id="@+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal"
android:padding="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_tick"
app:tint="@color/ColorWhite" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_10sdp"
android:layout_marginEnd="@dimen/_10sdp"
android:src="@drawable/ic_baseline_image_24"
app:tint="@color/ColorWhite" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_insert_link_24"
app:tint="@color/ColorWhite" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabCreateNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_add_24"
android:backgroundTint="@color/colorAccent"
android:tint="@color/ColorWhite"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="@dimen/_20sdp"
android:layout_marginBottom="@dimen/_20sdp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
And here is the Recyclerview Adapter
class NotesAdapter() :
RecyclerView.Adapter<NotesAdapter.NotesViewHolder>() {
var listener: OnItemClickListener? = null
var arrList = ArrayList<Notes>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotesViewHolder {
return NotesViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_rv_notes, parent, false)
)
}
override fun getItemCount(): Int {
return arrList.size
}
fun setData(arrNotesList: List<Notes>) {
arrList = arrNotesList as ArrayList<Notes>
}
fun setOnClickListener(listener1: OnItemClickListener) {
listener = listener1
}
override fun onBindViewHolder(holder: NotesViewHolder, position: Int) {
holder.itemView.tvTitle.text = arrList[position].title
holder.itemView.tvDesc.text = arrList[position].noteText
holder.itemView.tvDateTime.text = arrList[position].dateTime
if (arrList[position].color != null){
holder.itemView.cardView.setCardBackgroundColor(Color.parseColor(arrList[position].color))
}else{
holder.itemView.cardView.setCardBackgroundColor(Color.parseColor(R.color.ColorLightBlack.toString()))
}
if (arrList[position].pathImage != null) {
holder.itemView.imgNote.setImageBitmap(BitmapFactory.decodeFile(arrList[position].pathImage))
holder.itemView.imgNote.visibility = View.VISIBLE
} else {
holder.itemView.imgNote.visibility = View.GONE
}
if (arrList[position].webLink != "") {
holder.itemView.tvWebLink.text = arrList[position].webLink
holder.itemView.tvWebLink.visibility = View.VISIBLE
} else {
holder.itemView.tvWebLink.visibility = View.GONE
}
holder.itemView.cardView.setOnClickListener {
listener!!.onClicked(arrList[position].pld!!)
}
}
class NotesViewHolder(view: View) : RecyclerView.ViewHolder(view){
}
interface OnItemClickListener {
fun onClicked(noteId: Int)
}
}```