有人知道如何在 Realm 中使用卡片视图吗?

Someone knows how to use card views with Realm?

我想在我的应用程序中使用卡片视图,但我使用的是 Realm 数据库,非常感谢您提供简短的解释或示例。谢谢:)

因为 Realm 为您制作对象,您只需使用 getter 和 setter 方法来填充卡片上的视图。这将通过与您的 RecyclerView 关联的适配器或您正在使用的任何列表类型视图来完成。

卡片视图是用于向用户显示内容的用户界面。例如,包含用户姓名和年龄、用户图像等的卡片。而 Realm 是一个移动数据库,它存储用户的实际值,如姓名、年龄、图像路径等。

因此,您使用 Card View 来显示值,使用 Realm 来存储实际值。

可以进一步阅读卡片视图 here

并阅读 Realm 可以来自 here

public class User extends RealmObject {

    @PrimaryKey
    private String id;
    private String firstName;
    private String lastName;
    private int age;

public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

public String getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

In Your activity, You can store values to the Realm object like below,

User user = new User()
user.setFirstName("John")
user.setLastName("Kennedy")
user.setAge(40)

Realm realm = Realm.getInstance(this)
realm.executeTransaction {
                realm.copyToRealmOrUpdate(user)
            }
//Below is written in Kotlin language. You can find similar one in Java from the link given
val userJohn: User = realm.where(User::class.java)?.equalTo("firstName", "John").findFirst()

//Values of User John can be accessed like below
println(userJohn.firstName)
println(userJohn.lastName)
println(userJohn.age)

以上是Realm示例。

下面是一些卡片视图示例

http://code.tutsplus.com/tutorials/getting-started-with-recyclerview-and-cardview-on-android--cms-23465

http://javatechig.com/android/android-cardview-example

http://www.truiton.com/2015/03/android-cardview-example/