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()
}
}
}
}