Android FireStoreRecyclerAdapter仅在之前出现的内容之后显示结果?

Android FireStoreRecyclerAdapter仅在之前出现的内容之后显示结果?,android,firebase,android-recyclerview,google-cloud-firestore,firebaseui,Android,Firebase,Android Recyclerview,Google Cloud Firestore,Firebaseui,这将是一篇较长的帖子: 所以我有一个片段“Feed”,其中我所有的帖子都用FireStoreRecyclerAdapter列出,这很好用。每个帖子都有一个评论按钮,当我点击它时,它会启动一个名为“onClickPostActivity”的新活动,在这个活动中,帖子会再次加载,但在一个更大的视图中,可以使用屏幕底部的评论栏对其进行评论。在帖子下面,应该列出所有的评论,如果用户发布了一些东西,它应该立即更新并在帖子下面显示新的评论。一切正常这里唯一的问题是从命令加载 这就是问题所在: 图片1显示加

这将是一篇较长的帖子: 所以我有一个片段“Feed”,其中我所有的帖子都用FireStoreRecyclerAdapter列出,这很好用。每个帖子都有一个评论按钮,当我点击它时,它会启动一个名为“onClickPostActivity”的新活动,在这个活动中,帖子会再次加载,但在一个更大的视图中,可以使用屏幕底部的评论栏对其进行评论。在帖子下面,应该列出所有的评论,如果用户发布了一些东西,它应该立即更新并在帖子下面显示新的评论。一切正常这里唯一的问题是从命令加载

这就是问题所在:

图片1显示加载clickPostactivity时的图片。您会看到由于某种原因没有显示注释

那么在按下键盘后,它显然显示了帖子

在再次隐藏键盘后,它会按照从一开始就应该显示的方式显示注释

当我用后退按钮离开帖子并再次转到帖子时,这个过程会重复吗

以下是ClickPost活动的相关代码:



    @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();
    }



@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u单击\u发布);
setUpRecyclerView();
}
私有void setUpRecyclerView(){
Query Query=commentsRef.orderBy(“时间”,Query.Direction.DESCENDING);
FirestoreRecyclerOptions选项=新建FirestoreRecyclerOptions.Builder().setQuery(查询,注释.class).build();
适配器=新注释适配器(选项);
recyclerView.setHasFixedSize(true);
setLayoutManager(新建LinearLayoutManager(单击PostActivity.this));
recyclerView.setAdapter(适配器);
}
@凌驾
受保护的void onStart(){
super.onStart();
adapter.startListening();
}
@凌驾
受保护的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中)解决了此问题:


如果您遇到问题,最好在发布问题时创建一个。您为此问题发布了600多行代码。对于人们来说,在线解析和调试是非常困难的。请编辑您的问题并隔离问题,这样可以增加您获得帮助的机会。好的,我删除了所有内容,谢谢您
recyclerView.setHasFixedSize(true);