【发布时间】:2020-10-01 16:17:53
【问题描述】:
这将是一个更长的帖子: 所以我有一个片段“Feed”,其中我的所有帖子都与 FireStoreRecyclerAdapter 一起列出,这工作正常。每个帖子都有一个 cmets 按钮,当我单击它时,它会启动一个名为“onClickPostActivity”的新活动,该帖子会再次加载,但可以在更大的视图中使用屏幕底部的评论栏对其进行评论。然后应该在帖子下方列出所有 cmets,如果用户发布某些内容,它应该立即更新并在帖子下显示新评论。一切正常,这里唯一的问题是从评论中加载
这就是问题所在:
第一张图片显示了加载 clickPostactivity 时的图片,您看到 cmets 由于某种原因没有显示
所以在按下键盘后它显然会显示帖子?
再次隐藏键盘后,它会显示从一开始就应该显示的 cmets
当我使用返回按钮离开帖子并再次转到帖子时,该过程会重复吗?
这里是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>
【问题讨论】:
-
如果您遇到问题,最好在发布问题时创建MCVE。您为此问题发布了超过 600 行代码。人们需要解析和尝试在线调试的内容很多。请编辑您的问题并隔离问题,这样可以增加获得帮助的机会。
-
好的,我删除了东西
标签: android firebase android-recyclerview google-cloud-firestore firebaseui