0

I have 2 recycler views and one text view. What I am trying to do is when I click from top recyclerview(recyclerViewNotClickedItems) the items, they will disappear and they will appear in the bottom recyclerview(recyclerViewClickedItems).

My problem is that the TextView I have, I want it to go more up and up as I am clicking items from first recyclerview and they dissapear , and in the end since there are no items, the text view should be on the top of the screen.

Here is my code:

<RecyclerView
    android:id="@+id/recyclerViewNotClickedItems"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/settingsYouAlreadySeeTxt" />

<TextView
    android:id="@+id/settingsYouAlreadySeeTxt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/settings_you_already_seen"
    android:textSize="40sp"
    android:visibility="invisible"
    app:layout_constraintStart_toStartOf="@+id/recyclerViewNotClickedItems"
    app:layout_constraintTop_toBottomOf="@+id/recyclerViewNotClickedItems">

</TextView>

<RecyclerView
    android:id="@+id/recyclerViewClickedItems"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@+id/settingsYouAlreadySeeTxt"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent" />

And here is the implemented logic

 adapterCheckedList = RecyclerViewListAdapter()
 adapterNotCheckedList = RecyclerViewListAdapter(clickListener = { view: View, listItem: Any, position: Int ->
            binding.settingsYouAlreadySeeTxt.visibility = View.VISIBLE //Here, besides visibility i want to move it to the top everytime unCheckedList gets smaller.
            val removedItem =unCheckedList.removeAt(position)
            checkedList.add(removedItem)

            adapterNotCheckedList.submitList(unCheckedList)
            adapterCheckedList.submitList(removedItem)
        })

2 Answers 2

0

Let RecyclerView handle views ,you only handle data and then notice recyclerview data are changed.

adapterNotCheckedList = RecyclerViewListAdapter(clickListener = { view: View, listItem: Any, position: Int ->
    //Here, besides visibility i want to move it to the top everytime unCheckedList gets smaller.
    checkedList.add(unCheckedList.removeAt(position))
    // you need get adapter.
    topAdapter.notifyItemRemoved(position)
    bottomAdapter.notifyItemInserted(checkedList.lastIndex)
})

if unchecked list is too large ,you will only see top recyclerview.

Sign up to request clarification or add additional context in comments.

Comments

0
you can update you xml like
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RecyclerView
        android:id="@+id/recyclerViewNotClickedItems"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <TextView
        android:id="@+id/settingsYouAlreadySeeTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/settings_you_already_seen"
        android:textSize="40sp"
        android:visibility="invisible"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/recyclerViewNotClickedItems"
        app:layout_constraintBottom_toTopOf="@id/recyclerViewClickedItems" />

    <RecyclerView
        android:id="@+id/recyclerViewClickedItems"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/settingsYouAlreadySeeTxt"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
    

will help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.