你们有关于使用领域和Recyclerview的最佳实践吗?我知道这是一般性问题,但我在网上找不到任何内容.例如,我遇到了很多麻烦,试图在一行上实现简单的颜色变化.例如,考虑这种典型用法:
public class User extends RealmObject {
@PrimaryKey
String name;
boolean isSelected;
...
constructor, getter and setters
}
public class UserAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private RealmResults<User> users;
public UserAdapter(RealmResults<User> users) {
this.users = users;
}
...
public void markAsSelected(int position){
// get the old selected user and deselect it
notifyItemChanged(? how do i get the position given my User has no index ?);
// mark as selected the new user at position
}
Run Code Online (Sandbox Code Playgroud)
我遇到了很多问题,因为我在互联网上找不到任何东西.我知道这是因为我不知道如何正确使用领域.但找到正确的方法本身就是一场斗争.我阅读了他们所有的文档,但无济于事.
编辑:因为我被要求 - >而不是说"我有一堆问题",描述你的问题,我们将尝试提供你的不理解的见解和答案.
所以我的问题很简单:
我有一个RealmUser:
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试从服务器(JSON)获取 RealmList 的 RealmList 到领域对象。我正进入(状态
错误:RealmList 的元素类型必须是实现“RealmModel”的类或“java.lang.String”、“byte[]”、“java.lang.Boolean”、“java.lang.Long”、“java”之一.lang.Integer'、'java.lang.Short'、'java.lang.Byte'、'java.lang.Double'、'java.lang.Float'、'java.util.Date'。
{
"facilities": [
{
"facility_id": "1",
"name": "Property Type",
"options": [
{
"name": "Apartment",
"icon": "apartment",
"id": "1"
},
{
"name": "Condo",
"icon": "condo",
"id": "2"
},
{
"name": "Boat House",
"icon": "boat",
"id": "3"
},
{
"name": "Land",
"icon": "land",
"id": "4"
}
]
},
{
"facility_id": "2",
"name": "Number of Rooms",
"options": [
{
"name": "1 to 3 Rooms",
"icon": "rooms",
"id": "6"
},
{
"name": "No Rooms",
"icon": "no-room",
"id": …Run Code Online (Sandbox Code Playgroud)