0

I realise this question has been asked previously but the answers provided haven't helped me out. I cannot see what is going wrong here.

I have an activity, in which I display a bottom sheet, the bottom sheet has a title and a recyclerview. The recycler view is only displaying one item, regardless of how many are passed to the adapter. It is possible to scroll through the items but only one at any time is visible.

Here is my activity xml:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".features.order.automatedcheckout.view.AutomatedCheckoutQRCodeActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <TextView
        android:id="@+id/scanBarcodeInstruction"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginTop="50dp"
        android:text="Scan the barcode to get started"
        android:textSize="18sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/loadingGuideline"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.5"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
    <ProgressBar
        android:id="@+id/progressIndicator"
        app:layout_constraintBottom_toTopOf="@+id/loadingGuideline"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scanBarcodeInstruction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/qrcodeImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scanBarcodeInstruction"/>
    
    <TextView
        android:id="@+id/tenderName"
        app:layout_constraintTop_toBottomOf="@+id/qrcodeImageView"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:id="@+id/changeTenderButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"
        android:visibility="gone"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:text = "Change Tender"/>
</androidx.constraintlayout.widget.ConstraintLayout>

and here is my bottom sheet fragment xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bottomSheetLayout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <TextView
        android:id="@+id/tenderTitle"
        android:layout_marginTop="20dp"
        android:layout_marginStart="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SELECT"/>
    
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/tenderList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</androidx.appcompat.widget.LinearLayoutCompat>

my bottom sheet fragment:

class TenderBottomSheetFragment : BottomSheetDialogFragment() {
    private var _binding: FragmentTenderBottomSheetBinding? = null
    private val binding get() = _binding!!

    private lateinit var onTenderClicks:(tenderDetails: Pair<Int?, String?>) -> Unit

    lateinit var adapter: TenderAdapter

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentTenderBottomSheetBinding.inflate(inflater, container, false)
        adapter = TenderAdapter (
            arguments?.parcelableArrayList(ARG_TENDERS)!!,
            onTenderClicks
        )

        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val layoutManager = LinearLayoutManager(requireContext())
        binding.tenderList.layoutManager = layoutManager
        binding.tenderList.addItemDecoration(DividerItemDecoration(requireContext(), layoutManager.orientation))
        binding.tenderList.adapter = adapter
    }

    companion object {
        fun newInstance(
            campusTenders: List<TenderKt>,
            onTenderClick: (tenderDetails: Pair<Int?, String?>) -> Unit
        ): TenderBottomSheetFragment {
            val tenderDialogFragment = TenderBottomSheetFragment()
            tenderDialogFragment.onTenderClicks = onTenderClick
            tenderDialogFragment.apply {
                arguments = Bundle().apply {
                    putParcelableArrayList(ARG_TENDERS, ArrayList(tenders))
                }
            }
            return tenderDialogFragment
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}

I'm sure this is something really simple but unfortunately right now, I'm not seeing it. If anyone could help I would really appreciate it.

UPDATE Here is the recycler item layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    
    <TextView
        android:id="@+id/campus_tender_name"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:text ="Flex Account"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>

I have now updated that to:

<TextView
    android:id="@+id/campus_tender_name"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:padding="10dp"
    tools:text = "Flex Account"
    android:textSize="16sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

and that works fine. So it was the constraint layout in the recycler view item

DJ-DOO
  • 4,545
  • 15
  • 58
  • 98

0 Answers0