I'm populating a realm
database table with information from a Cloud Firestore collection. On the first load, the application opens and saves the information but does not display it until I close and open the application.
I need the information to be displayed after it's been written to the realm database. ie without having to close and open the app. I tried doing this by putting them in methods and in order in the onCreate method.
So after it has written all the information to the realm database I want the recyclerview to populate but I don't know how to do that, please help?
ScreenShots
First launch(left) and second launch(right)
OnCreate:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_import_user);
RelativeLayout = findViewById(R.id.contentuserimport);
// initialize realm
Realm.init(getApplicationContext());
//SETUP REEALM
RealmConfiguration defaultConfig = new RealmConfiguration.Builder()
.schemaVersion(0)
.build();
realm=Realm.getInstance(defaultConfig);
Intent intent = getIntent();
moduleID = intent.getStringExtra("moduleID");
moduleName = intent.getStringExtra("moduleName");
ButterKnife.bind(this);
init();
getAssessList();
}
Init():
private void init(){
linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
friendList.setLayoutManager(linearLayoutManager);
db = FirebaseFirestore.getInstance();
textView1.setText("Assessments - "+moduleName);
db.collection("assessment").whereEqualTo("module","xbIpNiDXGsIPmb5sTwbH").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
//GET DATA
Assessment a=new Assessment(Double.parseDouble(document.get("achieved").toString()),
document.get("date").toString(),document.get("desc").toString(),document.get("module").toString(),
document.get("time").toString(),Double.parseDouble(document.get("total").toString()),document.get("type").toString(),
document.get("weight").toString());
//SAVE
RealmHelper helper=new RealmHelper(realm);
helper.save(a);
}
}
}
});
//READ
RealmHelper helper=new RealmHelper(realm);
Assessment=helper.retrieve();
//BIND
adapter=new AssessAdapter(this,Assessment);
friendList.setAdapter(adapter);
adapter.notifyDataSetChanged();
friendList.setAdapter(adapter);
}
getAssessList():
private void getAssessList(){
//RETRIEVE
RealmHelper helper=new RealmHelper(realm);
Assessment=helper.retrieve();
//BIND
adapter=new AssessAdapter(this,Assessment);
friendList.setAdapter(adapter);
adapter.notifyDataSetChanged();
friendList.setAdapter(adapter);
}