I have a recycler view in my app and I am getting values from the user and storing it in the SQLite database and then those values will display in recycler view by retrieving. problem is that the recycler view is only updating when I reopen my activity so how can I refresh the recycler view without reopening the activity should I use UI thread? images: after inserting item
after reopen acitivty I want to display inserted item on recyclearview when the user click on the insert button
here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText=findViewById(R.id.ed1);
button=findViewById(R.id.INSERT);
name=new ArrayList<>() ;
id=new ArrayList<>();
recyclerView=findViewById(R.id.res);
database=new Database(MainActivity.this);
button.setOnClickListener(v -> {
database.insert(editText.getText().toString().trim());//insert
adapter.notifyDataSetChanged();
});
StoreDataInArray();//for store database data in array
adapter=new Adapter(name,id,MainActivity.this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
}