Passing from recyclerview to detailed activity

hi All,

I had some problem here for trying showing the detail information from recyclerView to detail activity.
The error is:

  • None of the following functions can be called with the arguments supplied: public constructor Intent(p0: Context!, p1: Class<*>!) defined in android.content.Intent public constructor Intent(p0: String!, p1: Uri!) defined in android.content.Intent
  • No value passed for parameter ‘p1’
  • No value passed for parameter ‘p2’

Here is code from ListViewAdapter

class ListBicycleAdapter(private val listBicycle: ArrayList<Bicycle>) :
    RecyclerView.Adapter<ListBicycleAdapter.ListViewHolder>() {


    override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ListViewHolder {
        val view: View = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_row_bicycle, viewGroup, false)
        return ListViewHolder(view)
    }

    override fun getItemCount(): Int {
        return listBicycle.size
    }

    override fun onBindViewHolder(holder: ListViewHolder, position: Int) {
        val bicycle = listBicycle[position]
        Glide.with(holder.itemView.context)
            .load(bicycle.photo)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .priority(Priority.HIGH)
            .into(holder.imgPhoto)
        holder.itemView.setOnClickListener {
            val intent = Intent(this, BicycleDetailed::class.java)
            intent.putExtra(listBicycle)[position]
            startActivity(intent)
        }
        holder.tvDetailed.text = bicycle.detail
        holder.tvName.text = bicycle.name
        holder.tvCountry.text = bicycle.country

    inner class ListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var tvName: TextView = itemView.findViewById(R.id.tv_item_name)
        var tvCountry: TextView = itemView.findViewById(R.id.tv_item_country)
        var imgPhoto: ImageView = itemView.findViewById(R.id.img_item_photo)
        var tvDetailed: TextView = itemView.findViewById(R.id.tv_item_detail)

    }

}

and here is my MainActivity

class MainActivity : AppCompatActivity() {
    private lateinit var rvBicycle: RecyclerView
    private var list: ArrayList<Bicycle> = arrayListOf()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        rvBicycle = findViewById(R.id.rv_bicycle)
        rvBicycle.setHasFixedSize(true)

        list.addAll(BicycleData.listData)
        showRecyclerList()

        var adapter = ListBicycleAdapter(list)
        rv_bicycle.setAdapter(adapter)

    }

    private fun showRecyclerList() {
        rvBicycle.layoutManager = LinearLayoutManager(this)
        val listBicycleAdapter = ListBicycleAdapter(list)
        rvBicycle.adapter = listBicycleAdapter
    }


    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.menu_main, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        setMode(item.itemId)
        return super.onOptionsItemSelected(item)
    }

    private fun showRecyclerGrid() {
        rvBicycle.layoutManager = GridLayoutManager(this, 1)
        val gridBicycleAdapter = GridBicycleAdapter(list)
        rvBicycle.adapter = gridBicycleAdapter
    }

    private fun setMode(selectedMode: Int) {
        when (selectedMode) {
            R.id.action_grid -> {
                showRecyclerGrid()
            }
            R.id.action_profile -> {
                val moveIntent = Intent(this@MainActivity, Profile::class.java)
                startActivity(moveIntent)
            }
            R.id.action_list -> {
                showRecyclerList()
            }
        }
    }
}

To indent your code, select your code and click on preformatted text

Sorry about that, I’m new in this community. Thanks for correct me.

haha, no worries, that’s exactly the reason I told you :wink:

Is Profile an Activity?

hehe… :ok_hand:

yes, the profile is activity. Is just show general information about me.

I think this you’re using is from ListBicycleAdapter. What if you try this:

val activity = holder.itemView.context as Activity
val intent = Intent(activity, BicycleDetailed::class.java)

Hopefully it’s working.

1 Like

Hi @ptdede

I just solved this case. But I am found a new issue here. If I am click the photo on ListView, my apps not displaying image , just the title and description.
Here is the code BicycleDetailed

   class BicycleDetailed : AppCompatActivity() {`

    companion object {
        const val EXTRA_NAME = "extra_name"
        const val EXTRA_DETAILED = "extra_detailed"

    }



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.item_detail_bicycle)


        showBicycleDetail()
    }

    private fun showBicycleDetail() {
        tv_item_name.setText(intent.getStringExtra(EXTRA_NAME))
        tv_item_detail.setText(intent.getStringExtra(EXTRA_DETAILED))

        var imgPhoto: ImageView = findViewById(R.id.img_item_photo)
        fun bind(bicycle: Bicycle) {
            Glide.with(this)
                .load(bicycle.photo)
                .into(imgPhoto)
        }
    }

}