我正在尝试在recyclerview中按时间顺序排列上传的照片,但出于某种原因,我的代码不起作用。
recyclerview适配器的代码:
private void setupAdapter() {
mPostAdapter = new FirebaseRecyclerAdapter<Post, PostHolder>(
Post.class,
R.layout.row_post,
PostHolder.class,
FirebaseUtils.getPostQuery()
) {
utils类的代码:
public static DatabaseReference getPostRef() {
return FirebaseDatabase.getInstance().getReference("posts");
}
public static Query getPostQuery() {
return getPostRef().orderByChild("timeCreated");
}
public static DatabaseReference getMyPostRef() {
return FirebaseDatabase.getInstance().getReference("my_posts")
.child(getCurrentUser().getEmail().replace(".", ","));
}
这是数据库结构:
{
...
"my_posts" : {
"a@aa,com" : {
"-KgHOJHOGHAPGyBuVbF5" : true
},
"afaf@sg,com" : {
"-KgHXFz3NoshQNKbXz53" : true,
"-KgHZJFpkQ7lxx7HcxEV" : true
},
...
},
"posts" : {
"-KgHOJHOGHAPGyBuVbF5" : {
"numComments" : 0,
"numLikes" : 0,
"postId" : "-KgHOJHOGHAPGyBuVbF5",
"postImageUrl" : "post_images/image:47620",
"postText" : "",
"timeCreated" : 1490662278306
},
...
},
"posts_liked" : {
"dskato0603@gmail,com" : {
"-KgWIDHRyVoX4kHQlCvk" : true
}
},
"user_record" : {
"a@aa,com" : {
"posts" : [ "-KgHOJHOGHAPGyBuVbF5" ]
},
"jxjsjskss@kfks,com" : {
"comments" : [ "-KgLRZCT7A_OIZXwa5RD", "-KgLRaAybYi9p1AnO5tN", "-KgMUAKOc30PBRwm5icX" ],
"posts" : [ "-KgHiMD5jlUcnHcLWcAi", "-KgL3MrPw2D6-N6VACKF", "-KgLDQxqaxVQNs9WcdEW" ]
}
...
}
}
答案 0 :(得分:0)
尝试一下:
LinearLayoutManager linearlayoutmanager = new LinearLayoutManager(context this);
linearlayoutmanager.setReverselayout(true);
linearlayoutmanager.setStackFromEnd(true);
RecyclerView.setLayoutManager(linearlayoutmanager);