2016-03-03 35 views

回答

2

卡片視圖是用戶界面,用於向用戶顯示您的內容。例如,包含用戶的名稱和年齡,用戶的圖像等的卡片。而Realm是移動數據庫,其存儲用戶的實際值,如姓名,年齡,圖像的路徑等。

因此,您使用卡片視圖來顯示值和Realm來存儲實際值。

更多關於卡片視圖閱讀了可以做到here

和境界上閱讀了可以從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) 

以上是境界實施例。

下面是一些卡片視圖例子

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/

+0

這是有用的信息,但也許你可以添加和應用這個2資源的例子,無論如何謝謝你:) –

+0

非常感謝你的伴侶:) –

0

由於Realm爲您製作對象,因此您只需使用getter和setter方法來填充卡片上的視圖。這可以通過與您的RecyclerView相關的適配器,或者您正在使用的任何List類型的View來完成。

+0

我知道,但我使用碎片這一點,所以我想這樣或具體信息一個應用的例子,謝謝反正隊友:D –

相關問題