I'm new to realm and i would like to know if this is the right way to use realm to populate my RecyclerView :
public class Offices extends AppCompatActivity {
RecyclerView recyclerView ;
OfficeAdapter officeAdapter;
List<Office> officeDataList;
List<Integer> officesImg;
Cursor cursor;
ArrayList<Office> DatabaseList;
Realm realm;
String[] OfficesNames;
String[] OfficesLocations;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offices);
realm = Realm.getDefaultInstance();
SetPathsData();
RealmResults <Office> Offices=realm.where(Office.class).findAll();
officeDataList = new ArrayList<>();
officeDataList.addAll(realm.copyFromRealm(Offices));
recyclerView = (RecyclerView) findViewById(R.id.recyclerview_paths);
officeAdapter = new OfficeAdapter(this , officeDataList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(officeAdapter);
}
private void SetPathsData() {
OfficesNames = new String[]{"أرونج تورز", "داماس هوليديز", "آرسيما","انجاز","بال تورز","بالكوم","المدينة تورز","بال ترحال","شركة ابناء نمر مرجان للحج والعمرة","شركة مشاعر للحج والعمرة"};
OfficesLocations = new String[]{"بديا","رام الله","بيت لحم","جنين","سلفيت","طولكرم","نابلس","الخليل","غزة","جنين"};
officesImg = new ArrayList<>();
officesImg.add(0,R.drawable.orange);
officesImg.add(1,R.drawable.damas);
officesImg.add(2,R.drawable.arsema);
officesImg.add(3,R.drawable.enjaz);
officesImg.add(4,R.drawable.paltours);
officesImg.add(5,R.drawable.palcom);
officesImg.add(6,R.drawable.almadena);
officesImg.add(7,R.drawable.palterhal);
officesImg.add(8,R.drawable.nemer);
officesImg.add(9,R.drawable.mashaer);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// Add a person
for (int i = 0; i < 9; i++) {
Office office = realm.createObject(Office.class ,i);
office.setOfficeName(OfficesNames[i]);
office.setOfficeImg(officesImg.get(i));
office.setOfficeLocation(OfficesLocations[i]);
}
}
});
}}
It's working fine , i just want to know if it's the right way to do it because i want to develop my whole application database using realm , so i don't want get any problem in the future.
How can i see my data using Realm Studio ?
Please let me know if there's something wrong .