0

I am currently using one recycler view which is Parent and vertical scrolls in home fragment, I search through resources but as learner I cant find anything useful, I WANT TWO RECYCLERS_VIEW WITH HEADINGS (ONE IS HORIZONTAL SCROLL(on top) AND SECOND ONE IS VERTICAL SCROLLS (below the horizontal one)). So, when I touch vertical scrollable recycler view, whole screen should move upwards. Also i dint touch my code because i can mess up with things so anyone can guide me :)

Here is my Parent Recycler View as of now, i want to add horizontal scroll recylerView on top of this in UI.

 <androidx.recyclerview.widget.RecyclerView
        android:layout_gravity="center_horizontal"
        android:id="@+id/recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@+id/recylerViewHorizontalScroll"
        tools:listitem="@layout/job_description_card_hori"
       />

here is MyAdapter,, so here i want to pass on the data in another card also named:- job_description_card_horizontal_scroll.xml

class MyAdapter(val context : Activity, val jobDetailsDataClass: List<job_details_data_class>) :
    RecyclerView.Adapter<MyAdapter.MyViewHolder>(){



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val itemView = LayoutInflater.from(context).inflate(R.layout.job_description_card_hori
            , parent, false)
        return MyViewHolder(itemView)
    }

    override fun getItemCount(): Int {
        return jobDetailsDataClass.size
    }
 override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val currentItem = jobDetailsDataClass[position]

        holder.brand_name.text = currentItem.businessName
holder.ratings.text = currentItem.ratings.toString()
}
   class MyViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){
        var job_name : TextView
        var brand_image : ShapeableImageView
        val ratings : TextView
        val rates : TextView
        val address :TextView
        val brand_name:TextView
        val rating_star_image_view : ImageView


       init {
            job_name = itemView.findViewById(R.id.job_name)
            brand_image = itemView.findViewById(R.id.brand_image)
            ratings = itemView.findViewById(R.id.ratings)
           rates = itemView.findViewById(R.id.rates)
           address= itemView.findViewById(R.id.address)
           brand_name = itemView.findViewById(R.id.brand_name)
           rating_star_image_view = itemView.findViewById(R.id.star_image_view_ratings)

        }
    }

}

HomeFragment.kt ,, this one taking the data from firebase and passing to adapter to populate the data needed, so any Changes is here, plsss :)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        dataInitialized()
        val layoutManager= LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL, false)

        filterRecyclerView = view.findViewById(R.id.recyclerViewFilter)
        filterRecyclerView.layoutManager = layoutManager
        filterRecyclerView.setHasFixedSize(true)
        Sort_header_recycler_Adpater1= Sort_header_recycler_Adpater(sorts_list_array)
        filterRecyclerView.adapter = Sort_header_recycler_Adpater1


        val jobsList = mutableListOf<job_details_data_class>()
        recyclerView = view.findViewById(R.id.recyclerView)
        myAdapter = MyAdapter(requireActivity(), jobsList)
                recyclerView.adapter = myAdapter
                recyclerView.layoutManager = LinearLayoutManager(requireActivity())




        val databaseRef = FirebaseDatabase.getInstance().reference.child("user_business")
        databaseRef.addValueEventListener(object : ValueEventListener {
            @SuppressLint("NotifyDataSetChanged")
            override fun onDataChange(dataSnapshot: DataSnapshot) {
                jobsList.clear()
                for (userBusinessSnapshot in dataSnapshot.children) {
                    val businessName = userBusinessSnapshot.child("businessName").value.toString()
                    val businessLogo = userBusinessSnapshot.child("businessLogo").value.toString()
                    val address = userBusinessSnapshot.child("address").value.toString()
                    val ratings = userBusinessSnapshot.child("ratings").value.toString().toDouble()

                    val formattedRatings = if (ratings > 5.0) "5.0".toDouble()
                    else ratings.toString().toDouble()


                    // Retrieve all the jobs for the current user
                    val jobsSnapshot = userBusinessSnapshot.child("Jobs")
                    for (jobSnapshot in jobsSnapshot.children) {
                        val jobId = jobSnapshot.key.toString()
                        val jobTitle = jobSnapshot.child("jobTitle").value.toString()
                        val payPerHour = jobSnapshot.child("payPerHour").value.toString()
                        val startTime = jobSnapshot.child("startTime").value.toString()
                        val endTime = jobSnapshot.child("endTime").value.toString()
                        val description = jobSnapshot.child("description").value.toString()
                        val durationInSeconds = jobSnapshot.child("durationInSeconds").value.toString().toLong()
                        val payPerDay = jobSnapshot.child("payPerDay").value.toString().toDouble()

                        val job = job_details_data_class(

                            businessName,
                            address,
                            businessLogo,
                            formattedRatings,
                            jobId,
                            jobTitle,
                            payPerHour,
                            startTime,
                            endTime,
                            description,
                            durationInSeconds,
                            payPerDay
                        )
//                       if (payPerDay > 0){
//                           jobsList.add(job)
//                       }
                        jobsList.add(job)

                    }
                }
                myAdapter.notifyDataSetChanged()
            }

            override fun onCancelled(error: DatabaseError) {
                Toast.makeText(activity, "unable to retrive data",
                    Toast.LENGTH_LONG).show()
            }
        })


    }

Also putting both recycler View in Scroll view is not actually working because it only scroll the whole screen when last item of vertical scroll recycler view comes on the screen.

expected current

Note:- all the brand images are not meant for marketing it's just for testing purpose :)

  • It sounds like you want a single RecyclerView (so the whole thing scrolls up and down), but with two kinds of ViewHolder - one that displays a single item card layout (used for most of the items) and one that contains a horizontal RecyclerView (only used for the first item). That way it's all part of the same list, so it all scrolls vertically, but you can also have horizontally scrolling sections within it (similar to the Play Store). I don't have time to write an implementation but that's the stuff you'd need to look into – cactustictacs May 19 '23 at 21:24
  • what about the headings, should I hard code both headings for respective views?? – Akhil Bhatnagar May 20 '23 at 02:50
  • by the way have you saw the attachement. @cactustictacs – Akhil Bhatnagar May 20 '23 at 11:06
  • You have two options for headers - either make those *another* kind of `ViewHolder` (more complicated) or make them a part of the item views, and either display or hide it (with visibility `GONE`) depending on whether the item is the first in a section. So in your case, the item with the horizontal `RecyclerView` would have a visible header, and the first item in the *Jobs to explore* section would have a visible header – cactustictacs May 20 '23 at 16:16
  • 1
    yeah that's great idea., "Arigatou" – Akhil Bhatnagar May 20 '23 at 16:40

0 Answers0