I want to update my Recycler View, so that whenever I delete a row from a table in a database, it updates the Recycler View at once without refreshing the fragment.
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View?
{
var binding:FragmentDisplayBinding = DataBindingUtil.inflate(inflater,R.layout.fragment_display,container,false)
var view:View = binding.root
var new_task : FloatingActionButton = view.findViewById(R.id.add_newTask)
var db = Room.databaseBuilder(context!!,tasksDb:: class.java,"mydb").allowMainThreadQueries().build()
viewManager = LinearLayoutManager(context)
recyclerView = view.findViewById(R.id.recyclerView)
db.task().getAll().observe(this, Observer {
this.myAdapter = myAdapter(it)
recyclerView.adapter = myAdapter
recyclerView.layoutManager = viewManager
})
I believe I should not use the .observe() in the onCreateView() method. What changes should I implement in the code ??