我一直在处理我的应用程序,我希望有一个片段,显示建议的用户,以便跟踪(显示数据库中的一些用户{{ 1}}但是当我设置我的child("users")
时,不会显示任何项目(个人资料)
继承我的片段布局:
RecyclerView
位于建议用户的正下方..它没有显示任何数据,
这是我的项目XML:
RecyclerView
这是我的<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="@dimen/_60sdp"
android:src="@drawable/profile"
android:id="@+id/user_in_list_image"
app:border_color="#fff"
android:layout_margin="@dimen/_10sdp"
app:border_width="3dp"
android:layout_height="@dimen/_60sdp" />
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="User203"
android:textStyle="bold"
android:id="@+id/user_in_list_username"
android:textSize="@dimen/_14sdp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="El Eulma, Algeria"
android:textSize="@dimen/_12sdp"
android:id="@+id/user_in_list_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.like.LikeButton
android:id="@+id/user_in_list_followButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
app:icon_size="@dimen/_16sdp"
app:is_enabled="true"
app:icon_type="thumb" />
</LinearLayout>
<RelativeLayout
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.like.LikeButton
android:layout_marginRight="@dimen/_30sdp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
app:icon_size="@dimen/_16sdp"
android:layout_gravity="center|end"
app:is_enabled="true"
app:icon_type="heart" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
java.class:
Object Model
这是我的public class User {
public String name;
public String gender;
public String birthday;
public String work;
public String country;
public String language;
public String city;
public String postal;
public User() {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public User(String name ,String gender, String birthday, String work , String country,String language , String city ,String postal) {
this.name = name;
this.gender = gender;
this.birthday = birthday;
this.work = work;
this.country = country;
this.language = language;
this.city = city;
this.postal = postal;
}
public String getName() { return name; }
public String getGender() { return gender; }
public String getBirthday() { return birthday; }
public String getWork() { return work; }
public String getCountry() { return country; }
public String getLanguage() { return language; }
public String getCity() { return city; }
public String getPostal() { return postal; }
}
java.class:
ViewHolder
这里是我的framgent.java public class users_holder extends RecyclerView.ViewHolder{
private static final String TAG = users_holder.class.getSimpleName();
public TextView userName,userInfo;
public CircleImageView userImage;
public com.like.LikeButton likeButton;
public users_holder(View itemView) {
super(itemView);
userName= itemView.findViewById(R.id.user_in_list_username);
userInfo = itemView.findViewById(R.id.user_in_list_info);
userImage = itemView.findViewById(R.id.user_in_list_image);
likeButton = itemView.findViewById(R.id.user_in_list_followButton);
}
}
:
onCreateView
我在做什么错误?当我不得不在外部类中设置 adapte r时,我看到其他版本就好了,谢谢!
答案 0 :(得分:2)
Peter Hadad 的答案在这里为我工作: Android ListView adapter not pushing individual items for chat app - Firebase-Ui 3.1 ,所以你需要使用它:
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
由于FirebaseListAdapter
使用侦听器检查firebase数据库中的更改,然后要监听数据,您需要在adapter.startListening()
中添加onStart()
才能显示数据在列表视图中。
然后在onStop()
内,您可以使用adapter.stopListening()
从适配器中删除侦听器和数据。