0

"In My Application ,I am allowing to add comments using "ListView" ,and using "FirebaseListAdapter", it works ,but it shows 1 item only, and i don't know if the problem in "Java code" or "xml code", i previewed related codes below, tip: this code is inside fragment,and i have used "FireBaseRecyclerAdapter" in other things and worked, but currently i face problem with Listview while i need to use it."

{   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();

}

    {

This is my .XML file:

 <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>
            }
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • You also should share the code whre you are getting the reference. In the meanwhile, if you are interested, **[this](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849)** is how you can retrieve data from a Firebase Realtime database and display it in a `RecyclerView` using `FirebaseRecyclerAdapter`. – Alex Mamo Apr 03 '18 at 09:32
  • I have added refs , Recyclerview works well with me , but FirebaseListAdapter is showing 1 item of 20 item ,so i don't know where the problem with it – user9376792 Apr 03 '18 at 09:46
  • See also the .XML file. – Alex Mamo Apr 03 '18 at 09:47
  • it is added after java code ,,,,,,tip this xml code is in card view – user9376792 Apr 03 '18 at 09:55
  • That's not correct. You are using the parten view using `android:visibility="invisible"`. Try to add only the views that you need as in my post. – Alex Mamo Apr 03 '18 at 09:58
  • haven't worked it is still showing 1 item, sry it worked thanks – user9376792 Apr 03 '18 at 10:14

1 Answers1

0

According to the latest comments and the edited post, the problem in the code was happening due the use of the following line of code:

android:visibility="invisible"

The partent view was always set as invisible. The problem was solved by setting the visibility as visible and by adding to the partent view only the necessary views.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193