Can anyone help mi solve this problem? I want to show list of users in the app.
Logcat error: E/RecyclerView: No adapter attached; skipping layout
User code
data class Users(val userId : String = "",
val name : String = "",
val email : String = "") {
}
UsersAdapter code
class UsersAdapter(var context : Context,
var userList : ArrayList<Users>) : RecyclerView.Adapter<UsersAdapter.UsersViewHolder>() {
inner class UsersViewHolder(val adapterBinding : UsersItemBinding)
: RecyclerView.ViewHolder(adapterBinding.root){}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UsersViewHolder {
val binding = UsersItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return UsersViewHolder(binding)
}
override fun onBindViewHolder(holder: UsersViewHolder, position: Int) {
holder.adapterBinding.friendUserName.text = userList[position].name
}
override fun getItemCount(): Int {
return userList.size
}
}
MainActivity code
2
Answers
As stated in your Log you haven’t attatched the adapter to your RecyclerView.
Try this in the MainActivity onCreate():
Sometimes when update you want your recylerview, you must notifyDataSetChanged().
Example