我试图将旧的FirebaseAdapter代码修改为新的适配器,但我无法弄清楚如何使用FirebaseOptions和Query来使用新的FirebaseAdapter。所以我尝试了相同的旧方法并修改了代码,但它现在显示此错误
public class OpeningPage extends Fragment {
public OpeningPage() {
// Required empty public constructor
}
private RecyclerView mUsersList;
private DatabaseReference mUsersDatabase;
private LinearLayoutManager mLayoutManager;
private View mMainView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
// View view= inflater.inflate(R.layout.fragment_opening_page,
container, false);
mMainView = inflater.inflate(R.layout.fragment_chats, container, false);
mUsersDatabase =
FirebaseDatabase.getInstance().getReference().child("Users");
mLayoutManager = new LinearLayoutManager(getContext());
mUsersList = (RecyclerView) mMainView.findViewById(R.id.users_list);
mUsersList.setHasFixedSize(true);
mUsersList.setLayoutManager(mLayoutManager);
return mMainView;
}
@Override
public void onStart() {
super.onStart();
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("Users")
.limitToLast(50);
FirebaseRecyclerOptions<Users> options =
new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(query, Users.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Users,
UsersViewHolder>(options) {
@Override
protected void onBindViewHolder(UsersViewHolder holder, int
position, Users model) {
holder.setDisplayName(model.getName());
holder.setUserStatus(model.getStatus());
holder.setUserImage(model.getThumb_image(), getContext());
final String user_id = getRef(position).getKey();
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent profileIntent = new Intent(getActivity(),
ProfileActivity.class);
profileIntent.putExtra("user_id", user_id);
startActivity(profileIntent);
}
});
}
@Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int
viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.users_single_layout, parent, false);
return new UsersViewHolder(view);
}
};
mUsersList.setAdapter(adapter);
}
public static class UsersViewHolder extends RecyclerView.ViewHolder {
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setDisplayName(String name){
TextView userNameView = (TextView)
mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
public void setUserStatus(String status){
TextView userStatusView = (TextView)
mView.findViewById(R.id.user_single_status);
userStatusView.setText(status);
}
public void setUserImage(String thumb_image, Context ctx){
CircleImageView userImageView = (CircleImageView)
mView.findViewById(R.id.user_single_image);
Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar)
.into( userImageView);
}
}
}
我的适配器新代码是
NVARCHAR
早些时候我使用的是PopulateViewHolder但是在将我的gradle升级到之后 实现'com.firebaseui:firebase-ui-database:3.0.0' 它不再工作了。 提前致谢