• 15

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I'm trying to associate my RecyclerView adapter with a fragment but it is expecting another parameter at the adapter creation stage. I understand that something to do with fm needs to be included in the parameter but I'm not sure what I need to go there.

No value passed for parameter 'fm'

RecyclerView adapter class

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.companyname.appname.*
import com.google.android.flexbox.FlexboxLayout
import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.fragment_dialog.view.*

class MyRVAdapter(private val myList: ArrayList<Item>, private val fm: FragmentManager) : RecyclerView.Adapter<MyRVAdapter.ViewHolder>() {
    override fun getItemCount(): Int {
        return myList.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.myBtn.text = (myList[position].textBtnTitle)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val v = LayoutInflater.from(parent.context).inflate(R.layout.my_cv, parent, false)

        return ViewHolder(v)

    class ViewHolder (itemView : View):RecyclerView.ViewHolder(itemView) {
        val myBtn = itemView.findViewById<Button>(R.id.btn_a)!!

        init {
            myBtn.setOnClickListener {
                val builder = AlertDialog.Builder(myBtn.context)
                builder.setPositiveButton(android.R.string.ok){ dialog, _ -> dialog.dismiss() }

                val dialog: AlertDialog = builder.create()

                tabLayout = customView.findViewById(R.id.mTabLayout)
                viewPager = customView.findViewById(R.id.mViewPager)

                val adapter = TabbedDialogAdapter(fm)
                adapter.addFragment("Tab A", TabbedDialogFragment.createInstance("Description A"))
                adapter.addFragment("Tab B", TabbedDialogFragment.createInstance("Description B"))
                adapter.addFragment("Tab C", TabbedDialogFragment.createInstance("Description C"))

                customView.mViewPager.adapter = adapter


import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

class TabbedDialogAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
    private var mFragmentCollection: MutableList<Fragment> = ArrayList()
    private var mTitleCollection: MutableList<String> = ArrayList()
    fun addFragment(title: String, fragment: Fragment) {

    override fun getPageTitle(position: Int): CharSequence? {
        return mTitleCollection[position]

    override fun getItem(position: Int): Fragment {
        return mFragmentCollection[position]

    override fun getCount(): Int {
        return mFragmentCollection.size

fragment class

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.companyname.appname.R
import com.companyname.appname.MyRVAdapter
import java.util.*

class MyFragment : androidx.fragment.app.Fragment() {
    private lateinit var mRecyclerView: RecyclerView

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_rv, container, false)

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        val v = view

        mRecyclerView = v!!.findViewById<RecyclerView>(R.id.my_recyclerview)

        mRecyclerView.layoutManager = LinearLayoutManager(activity)

        val myList = ArrayList<Item>()

        val mAdapter = MyRVAdapter(myList)

        mRecyclerView.adapter = mAdapter

    • I looked over it, I haven't attempted to build it. The error would make sense if you failed to pass a fragment manager to TabbedDialogAdapter, but it doesn't make sense in the context you describe.
      • 1
    • Here: val mAdapter = RVAdapterFacilities(facilitiesList) aren't here missing additional parameter getFragmentManager()?
    • @MacaronLover so that means you are missing a parameter which you have in constructor of your adapter here: class MyRVAdapter(private val myList: ArrayList, private val fm: FragmentManager) so when you called adapter you provided only a list but missed getFragmentManager()

I think it is a simple solution. You just forgot to provide one parameter. In your adapter constructor you have ArrayList and FragmentManager:

class MyRVAdapter(private val myList: ArrayList<Item>, private val fm: FragmentManager)

but when you called your adapter here: val mAdapter = MyRVAdapter(myList) you provided only ArrayList so one parameter is missing, and that is probably getFragmentManager() if adapter is created in Fragment in Activity it would be getSupportFragmentManager()

  • 1
Reply Report
      • 1
    • Probably have selected (imported) wrong FragmentManager. Check imports on the top do you need: android.app.FragmentManager or android.support.v4.app.FragmentManager?
      • 2
    • I got androidx.fragment.app.FragmentManager. Just to clarify do I need to use fragmentManager or childFragmentManager?
      • 1
    • Ah yes you are using androidx than check did you imported androidx.fragment.app.FragmentManager and not using some another like I mentioned above
      • 1
    • I imported androidx.fragment.app.FragmentManager for all necessary classes. Should I be using childFragmentManager maybe?