I'm trying to display list items in a ListView using Realm offline database. I followed some tutorial and he used allObjects() method that cannot be resolved with me!!
Can you help me in this?
Here is my code:
@Override
protected void onResume() {
super.onResume();
Realm.init(getApplicationContext());
RealmConfiguration config = new RealmConfiguration.
Builder().
deleteRealmIfMigrationNeeded().
build();
Realm.setDefaultConfiguration(config);
Realm realm = Realm.getInstance(config);
realm.beginTransaction();
List<Car> cars = realm.**allObjects**(Car.class);
String[] names = new String[cars.size()];
for(int i=0; i<names.length;i++){
names[i]=cars.get(i).getName();
}
ListView listView = (ListView)findViewById(R.id.listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,names);
listView.setAdapter(adapter);
}
realm.beginTransaction();
You don't need that.
List<Car> cars = realm.**allObjects**(Car.class);
realm.allObjects(Car.class)
was replaced with realm.where(Car.class).findAll()
. Specifically, allObjects
was deprecated in 0.90.0, and removed in 0.91.0, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With