Android – read from realm.io and add to listview

I want to use realm.io to save data, and then display each item in the list view. This is how I create the database (I think):

config = new RealmConfiguration.Builder(this)
            .name("timeLog")
            .schemaVersion(42)
            .build();

realm.setDefaultConfiguration(config);

Then, when I save the data, do the following:

    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    timeData logTime = realm.createObject(timeData.class);
    logTime.setWorkedHours(timeTotal);
    realm.commitTransaction();
    System.out.println(logTime);
    System.out.println(logTime.getId());

Now, I want to add it to the array and display it in the list view. So I think I can do 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++){
        System.out.println(arrayList.add(result.get(i)));
    }

It's no use. And I don't know if the database I originally created still can't be found on the phone

to update

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

resolvent:

The root cause is that the op did not create a custom adapter. Listview requires that a class be created, which extends from the type of the adapter purposeful to each use case, and at least overrides the getview () method

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>