【问题标题】:ListView Showing 1 result using FirebaseListAdapterListView 使用 FirebaseListAdapter 显示 1 个结果
【发布时间】:2018-04-02 19:45:58
【问题描述】:

“在我的应用程序中,我允许使用“ListView”添加 cmets,并使用“FirebaseListAdapter”,它可以工作,但它只显示 1 个项目,我不知道问题是否在“ Java code" 或 "xml code",我在下面预览了相关的codes, 提示:这个codefragment 内部,我在其他事情上使用了“FireBaseRecyclerAdapter”并且工作正常,但目前我在需要使用它时遇到了Listview 的问题。”

{   DatabaseReference commentsdb = mydatabase.getReference().child("comments");
  Query commentsquery = commentsdb.child(storyNAME).orderByChild("currentstoryname").equalTo(storyNAME).limitToFirst(10);

FirebaseListOptions<comments> options = new FirebaseListOptions.Builder<comments>()
            .setQuery(commentsquery, comments.class)
            .setLayout(R.layout.comments)
            .setLifecycleOwner(this)
            .build();
                                         fbla= new FirebaseListAdapter<comments>(options) {
                                        @Override
                                        protected void populateView(View v, comments model, int position) {

                                            ((TextView)v.findViewById(id.commentername)).setText(model.getUserName1());

                                            ((TextView)v.findViewById(id.commentstxt1)).setText(model.getUsercomment());
            comlist.setAdapter(fbla);
    fbla.startListening();

}

    {

这是我的 .XML 文件:

 <LinearLayout
        android:id="@+id/commentsview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="invisible"
        ><ImageButton
        android:background="@drawable/ic_clear_24dp"
        android:id="@+id/cmtexitbtn"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        />
<ListView
          android:id="@+id/commentslist"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:listitem="@layout/comments"
          android:layout_marginBottom="5dp"/>
       <!--</LinearLayout>-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"><ImageButton
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:cropToPadding="true"
                android:id="@+id/comerimg"
                android:background="@drawable/imgstyle"
                android:clickable="false"
                /><EditText
                android:hint="type your comment"
                android:layout_weight="1"
                android:id="@+id/usernewcomment"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_margin="5dp"
                android:background="@drawable/normaledittextsty" />
                <Button
                    android:defaultFocusHighlightEnabled="true"
                android:id="@+id/sendcombtn"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@drawable/ic_send_24dp"/>
            </LinearLayout>
            }

【问题讨论】:

  • 您还应该在获得参考时分享代码。同时,如果您有兴趣,this 是您可以从 Firebase 实时数据库中检索数据并使用 FirebaseRecyclerAdapter 将其显示在 RecyclerView 中的方法。
  • 我添加了 refs,Recyclerview 很适合我,但是 FirebaseListAdapter 显示的是 20 项中的 1 项,所以我不知道问题出在哪里
  • 另见 .XML 文件。
  • 在java代码之后添加,,,,,,tip this xml code is in card view
  • 这不正确。您正在使用android:visibility="invisible" 使用parten 视图。尝试仅添加您在我的帖子中需要的视图。

标签: java android firebase firebase-realtime-database android-cardview


【解决方案1】:

根据最新的cmets和编辑后的帖子,代码中的问题是由于使用了以下代码行:

android:visibility="invisible"

partent 视图始终设置为invisible。通过将可见性设置为 visible 并仅将必要的视图添加到部分视图中,问题已得到解决。

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 2015-08-24
    • 2017-11-04
    • 2017-02-17
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    相关资源
    最近更新 更多