Kotlin/Android | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

Kotlin/Android

How to start new activity by clicking an item in recycler view and also pass data to new activity while doing this?(using Kotlin) Thanks in advanced.

14th Oct 2018, 7:32 AM
Rstar
Rstar - avatar
4 Answers
+ 1
I haven't used kotlin for android yet but have been using java. In java, you need to set an onClicklistener on the itemview in the adapter you have used with recyclerview. There is no direct listener which can be set on recyclerview for an item. I guess the same thing applys in kotlin. Hope it helps.
15th Oct 2018, 10:47 AM
Usman Khan
Usman Khan - avatar
+ 1
It's basically like Java. The easiest way would be is to set an onclicklistener to the "viewHolder" in onBindViewholder and then call startActivity(intent); intent.putExtra("INDEX",data);
22nd Oct 2018, 8:19 AM
Twenty-three
+ 1
activity to activity just to pass data is not good idea. use fragments instead. you just have to call this@<activity-class>.getActivity().field
22nd Oct 2018, 7:45 PM
Mohsen Cadir
Mohsen Cadir - avatar
- 3
c++
15th Oct 2018, 1:49 AM
Jade Aguilando II
Jade Aguilando II - avatar