"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>
}