how to create secondary constructor in recycler adapter taking arraylist parameter in kotlin android studio
Solution 1:
Please use these constructors:
class CustomRecyclerAdapter constructor(
val context: Context,
val topics: Array<String> = emptyArray(),
private var alist: ArrayList<String>
) : RecyclerView.Adapter<CustomRecyclerAdapter.ViewHolder>() {
constructor(context: Context, sss: ArrayList<String>) : this(context, alist = sss)
// ...
}
In the primary constructor you need to specify a default value for topics
. Also add context: Context
parameter to the secondary constructor and pass it to this()
when calling the primary constructor.