FireStoreRecyclerAdapter 只在它之前出现的东西之后才显示结果?
FireStoreRecyclerAdapter only showing results after something appearing before it?
这会更长 post:
所以我有一个 Fragment "Feed",其中我所有的 post 都与 FireStoreRecyclerAdapter 一起列出,并且工作正常。每个 post 都有一个评论按钮,当我点击它时,它会启动一个名为 "onClickPostActivity" 的新 activity,其中 post 会再次加载,但在更大的视图中能够使用屏幕底部的评论栏对其进行评论。在 post 下面应该列出所有评论,如果用户 post 有东西,它应该立即更新并在 post 下显示新评论。一切正常,这里唯一的问题是从评论中加载
这是问题所在:
第一张图片显示了加载 clickPostactivity 时的图片您看到评论由于某种原因没有显示
所以在按下键盘后它显然显示 posts ?
再次隐藏键盘后,它会显示从一开始就应该显示的注释
当我使用后退按钮离开 post 并再次转到 post 时,过程会重复吗?
这里是clickPostActivity的相关代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_click_post );
setUpRecyclerView();
}
private void setUpRecyclerView() {
Query query = commentsRef.orderBy("time", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Comments> options = new FirestoreRecyclerOptions.Builder<Comments>().setQuery(query, Comments.class).build();
adapter = new CommentsAdapter(options);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(clickPostActivity.this));
recyclerView.setAdapter(adapter);
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
如果是 xml 布局文件的错误,这里有一些奇怪的原因:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context=".clickPostActivity">
<include
android:id="@+id/toolbar"
layout="@menu/toolbar"/>
<include
android:id="@+id/commentbar"
layout="@menu/commentbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="50dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/og_profileImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_action_profile"
android:scaleType="centerCrop"
android:layout_marginLeft="4dp">
</de.hdodenhof.circleimageview.CircleImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/og_userName"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@font/abel"
android:maxLines="1"
android:text="username"
android:textAlignment="textStart"
android:textColor="@android:color/white"
android:textSize="16dp"
android:textStyle="bold"
android:layout_width="330dp" />
<ImageButton
android:id="@+id/og_postOptions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_action_options"></ImageButton>
</LinearLayout>
<TextView
android:id="@+id/og_uploadTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="posted at 23:11 on Semptember 11th 2020"
android:textSize="13dp"
android:textColor="@android:color/white"></TextView>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/og_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Post description"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:padding="3dp"
android:textSize="14dp"
android:textColor="@android:color/white" />
<ImageView
android:id="@+id/og_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/og_commentList"
android:layout_width="match_parent"
android:layout_height="wrap_content"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="@+id/comment_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:background="#9A39B54A"
android:orientation="vertical">
<TextView
android:id="@+id/post_delete_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/abel"
android:text="Delete Post"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/comment_delete_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:fontFamily="@font/abel"
android:text="Confirm"
android:textColor="@android:color/white" />
<Button
android:id="@+id/comment_delete_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:fontFamily="@font/abel"
android:text="Cancel"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我遇到了同样的问题并通过删除这部分(它在您的 clickPostActivity 中)解决了这个问题:
recyclerView.setHasFixedSize(true);
这会更长 post: 所以我有一个 Fragment "Feed",其中我所有的 post 都与 FireStoreRecyclerAdapter 一起列出,并且工作正常。每个 post 都有一个评论按钮,当我点击它时,它会启动一个名为 "onClickPostActivity" 的新 activity,其中 post 会再次加载,但在更大的视图中能够使用屏幕底部的评论栏对其进行评论。在 post 下面应该列出所有评论,如果用户 post 有东西,它应该立即更新并在 post 下显示新评论。一切正常,这里唯一的问题是从评论中加载
这是问题所在:
第一张图片显示了加载 clickPostactivity 时的图片您看到评论由于某种原因没有显示
所以在按下键盘后它显然显示 posts ?
再次隐藏键盘后,它会显示从一开始就应该显示的注释
当我使用后退按钮离开 post 并再次转到 post 时,过程会重复吗?
这里是clickPostActivity的相关代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_click_post );
setUpRecyclerView();
}
private void setUpRecyclerView() {
Query query = commentsRef.orderBy("time", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Comments> options = new FirestoreRecyclerOptions.Builder<Comments>().setQuery(query, Comments.class).build();
adapter = new CommentsAdapter(options);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(clickPostActivity.this));
recyclerView.setAdapter(adapter);
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
如果是 xml 布局文件的错误,这里有一些奇怪的原因:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context=".clickPostActivity">
<include
android:id="@+id/toolbar"
layout="@menu/toolbar"/>
<include
android:id="@+id/commentbar"
layout="@menu/commentbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="50dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/og_profileImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_action_profile"
android:scaleType="centerCrop"
android:layout_marginLeft="4dp">
</de.hdodenhof.circleimageview.CircleImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/og_userName"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@font/abel"
android:maxLines="1"
android:text="username"
android:textAlignment="textStart"
android:textColor="@android:color/white"
android:textSize="16dp"
android:textStyle="bold"
android:layout_width="330dp" />
<ImageButton
android:id="@+id/og_postOptions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_action_options"></ImageButton>
</LinearLayout>
<TextView
android:id="@+id/og_uploadTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="posted at 23:11 on Semptember 11th 2020"
android:textSize="13dp"
android:textColor="@android:color/white"></TextView>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/og_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Post description"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:padding="3dp"
android:textSize="14dp"
android:textColor="@android:color/white" />
<ImageView
android:id="@+id/og_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/og_commentList"
android:layout_width="match_parent"
android:layout_height="wrap_content"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="@+id/comment_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:background="#9A39B54A"
android:orientation="vertical">
<TextView
android:id="@+id/post_delete_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/abel"
android:text="Delete Post"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/comment_delete_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:fontFamily="@font/abel"
android:text="Confirm"
android:textColor="@android:color/white" />
<Button
android:id="@+id/comment_delete_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:fontFamily="@font/abel"
android:text="Cancel"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我遇到了同样的问题并通过删除这部分(它在您的 clickPostActivity 中)解决了这个问题:
recyclerView.setHasFixedSize(true);