title: Save API data in Room database in Android
body: <p>I want to take the data from API using retrofit and save them in room database. Then populate my Adapter, I added the data in Room but when the list with data shows to me when I click an element of the list of users I click to X user and it shows me the data for another user.  I haven't figured out where is my problem
  Here is my code:</p>
  
  <pre><code>class TutorsFragment : Fragment(), TutorListAdapter.ListItemClickListener, fromBackgroundToMainUIThread {
  
  
  private var recyclerView: RecyclerView? = null
  private var tutorListAdapter: TutorListAdapter? = null
  private lateinit var tutors: List&lt;Tutors&gt;
  private lateinit var tutorViewModel: StudentTutorViewModel
  
  override fun onTutorsReceived(tutors: List&lt;Tutors&gt;) {
      this.tutors = tutors
  }
  
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      val tutorView = inflater.inflate(R.layout.fragment_tutors, null)
  
      recyclerView = tutorView.findViewById&lt;View&gt;(R.id.recyclerview_tutors) as RecyclerView
      tutorViewModel = ViewModelProviders.of(this).get(StudentTutorViewModel::class.java)
  
      val layoutManager = LinearLayoutManager(this.activity, LinearLayoutManager.VERTICAL, false)
      recyclerView!!.layoutManager = layoutManager
  
      recyclerView!!.setHasFixedSize(true)
  
      tutorViewModel.getAllTutors().observe(viewLifecycleOwner, Observer {
          if (it != null) {
              tutorListAdapter = TutorListAdapter(it as MutableList&lt;Tutor&gt;?, this@TutorsFragment)
              recyclerView!!.adapter = tutorListAdapter
          }
      })
  
      val api = RetrofitClient.getInstance().apiService
      val call = api!!.tutorsList
  
      call.enqueue(object : Callback&lt;List&lt;Tutors&gt;&gt; {
          override fun onResponse(call: Call&lt;List&lt;Tutors&gt;&gt;, response: Response&lt;List&lt;Tutors&gt;&gt;) {
  
              Log.d("Tutors:  ", response.toString())
              val tutorsList = response.body()
  
              tutorsList!!.forEach {
                  val tutor = Tutor(it.userID!!, it.name!!, it.lastname!!, it.email!!, it.roleFK!!, it.course!!.pathName)
                  tutorViewModel.addTutor(tutor)
              }
  
              if (true) {
                  this@TutorsFragment.onTutorsReceived(tutorsList)
              }
  
          }
  
          override fun onFailure(call: Call&lt;List&lt;Tutors&gt;&gt;, t: Throwable) {
              Toast.makeText(activity!!.applicationContext, t.message, Toast.LENGTH_SHORT).show()
          }
      })
  
      }
  
      val fab = tutorView.findViewById&lt;View&gt;(R.id.fab_tutors) as FloatingActionButton
      fab.setOnClickListener {
          val fragment = AddStudentAndTutorFragment()
          val title = "Add Tutors"
          val fragmentManager = fragmentManager
          val ft = fragmentManager!!.beginTransaction()
          ft.replace(R.id.frame, fragment)
          ft.addToBackStack(null)
          ft.commit()
  
          (activity as AppCompatActivity).supportActionBar!!.setTitle(title)
      }
  
      return tutorView
  }
  
  override fun onListItemClick(view: View, position: Int) {
  
      val tutor = tutors[position]
      val fragment = UserDetails()
      val title = "User Details"
      val bundle = Bundle()
      bundle.putString("name", tutor.name)
      bundle.putString("lastname", tutor.lastname)
      bundle.putString("email", tutor.email)
      bundle.putInt("userID", tutor.userID!!)
      bundle.putInt("role", tutor.roleFK!!)
      bundle.putString("course", tutor.course!!.pathName)
      fragment.arguments = bundle
  
      val fragmentManager = fragmentManager!!
      val ft = fragmentManager.beginTransaction()
      ft.replace(R.id.frame, fragment)
      ft.addToBackStack(null)
      ft.commit()
  
      (activity as AppCompatActivity).supportActionBar!!.title = title
  
  }
  
  override fun onResume() {
      super.onResume()
      val activity = activity as AppCompatActivity?
      val actionBar = activity!!.supportActionBar
      val my_fragment_title = "Tutors"
      actionBar!!.title = my_fragment_title
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>internal interface fromBackgroundToMainUIThread {
  fun onTutorsReceived(tutors: List&lt;Tutors&gt;)
  </code></pre>
  
  <p>}</p>
  
  <p>And Here is my Adapter class:</p>
  
  <pre><code>class TutorListAdapter(private val tutorsList: MutableList&lt;Tutor&gt;?, private val onItemClickListener: ListItemClickListener) : RecyclerView.Adapter&lt;TutorListAdapter.ListViewHolder&gt;() {
  
  override fun onCreateViewHolder(viewGroup: ViewGroup, viewtype: Int): ListViewHolder {
  
      return ListViewHolder(viewGroup.inflate(R.layout.list_item))
  }
  
  override fun getItemCount(): Int {
      return tutorsList!!.size
  }
  
  @SuppressLint("SetTextI18n")
  override fun onBindViewHolder(listViewHolder: ListViewHolder, position: Int) {
  
      val tutors = tutorsList!![position]
      listViewHolder.listItemTextView.text = tutors.name + "  " + tutors.lastname
  }
  
  fun removeItem(position: Int) {
      if (position &lt; 0 || position &gt;= tutorsList!!.size) {
          return
      }
  
      tutorsList.removeAt(position)
      notifyItemRemoved(position)
      notifyDataSetChanged()
  
  }
  
  interface ListItemClickListener {
  
      fun onListItemClick(view: View, position: Int)
  }
  
  inner class ListViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
      var listItemTextView: TextView
  
      init {
  
          listItemTextView = view.findViewById&lt;View&gt;(R.id.list_item_textview) as TextView
          view.setOnClickListener(this)
      }
  
      override fun onClick(v: View) {
          onItemClickListener.onListItemClick(v, adapterPosition)
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>ViewModel class:</p>
  
  <pre><code>class StudentTutorViewModel(application: Application) : AndroidViewModel(application) {
  
  var repository: Repository = Repository(application)
  
  fun addTutor(tutor: Tutor) = repository.addTutor(tutor)
  
  fun getAllTutors() = repository.getTutors()
  </code></pre>
  
  <p>}</p>
  
  <p>I would appreciate it if anyone can help me</p>