alexander mogren alexander mogren - 1 year ago 150
Android Question

Read from and add to listview

I want to use to save data and then display each item in a listview.
Here is how I have create the database (I think):

config = new RealmConfiguration.Builder(this)


Then after this when I save my data I do the following:

Realm realm = Realm.getDefaultInstance();
timeData logTime = realm.createObject(timeData.class);

And now I want to add this to an array maybe and display it in a listview.
So I thought i could make something like this:

RealmResults<timeData> result = realm.where(timeData.class).findAll();
result = result.sort("sgnumber", Sort.DESCENDING);
ArrayList<timeData> arrayList = new ArrayList();
for(int i = 0;i<result.size()-1;i++){

This did not work. And also I dont know if the db i created in the first place, cant find it on the phone anyway.


listview = (ListView)findViewById(;
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);

Answer Source

The root cause was that the OP was not creating a custom adapter. A ListView requires the creation of a class that extends from a type of adapter purposeful to each use case and override at least the getView() method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download