我将OnBindViewHolder放置在束缚我的模型并填充我的回收范围内的内容



现在,我只是尝试使用firebase UI 3.1.1来填充回收器视图。我所看到的所有教程都过时了,而过时的教程是不完整的。这就是我到目前为止的……

private void setUpFirebaseAdapter() {
    DatabaseReference reference = FirebaseDatabase.getInstance().getReference(Constants.LOBBIES);
    Query query = reference;
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    FirebaseRecyclerOptions lobbyOptions = new FirebaseRecyclerOptions.Builder<Lobby>().setQuery(query, Lobby.class).build();
    mLobbyAdapter = new FirebaseRecyclerAdapter<Lobby, LobbyViewHolder>(lobbyOptions) {
        @Override
        protected void onBindViewHolder(@NonNull LobbyViewHolder holder, int position, @NonNull Lobby model) {
            holder.
        }
        @Override
        public LobbyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return null;
        }
    };
}

我可以放入什么持有人,以便我可以完成回收器视图?谢谢!

编辑。这也是我的视图持有人班

public class LobbyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    View mView;
    Context mContext;
    public LobbyViewHolder(View itemView) {
        super(itemView);
        mView = itemView;
        mContext = itemView.getContext();
        itemView.setOnClickListener(this);
    }
    public void bindLobby(Lobby lobby) {
    TextView nameTextView = (TextView)     mView.findViewById(R.id.lobby_name_text);
    TextView locationTextView = (TextView) mView.findViewById(R.id.lobby_location_text);
    TextView sizeTextView = (TextView) mView.findViewById(R.id.lobby_size_text);
    TextView priceTextView = (TextView) mView.findViewById(R.id.lobby_price_text);
    TextView dateTextView = (TextView) mView.findViewById(R.id.lobby_date_text);
    nameTextView.setText(lobby.getOwner());
    locationTextView.setText(lobby.getLocation());
    sizeTextView.setText(lobby.getTotalMembers());
    priceTextView.setText("Php " + lobby.getCost());
    dateTextView.setText(lobby.getDateText());
    }
@Override
public void onClick(View v) {
    final ArrayList<Lobby> lobbies = new ArrayList<>();
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference(Constants.LOBBIES);
    ref.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot snapshot : dataSnapshot.getChildren()){
                lobbies.add(snapshot.getValue(Lobby.class));
            }
            int itemPosition = getLayoutPosition();
            Intent intent = new Intent(mContext, LobbyDetailActivity.class);
            intent.putExtra("position", itemPosition  + "");
            intent.putExtra("lobbies", Parcels.wrap(lobbies));
            mContext.startActivity(intent);
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}

}

从我看到的东西也没有夸大布局视图(oncreateviewholder(,这样做:

private void setUpFirebaseAdapter() {
    DatabaseReference reference = FirebaseDatabase.getInstance().getReference(Constants.LOBBIES);
    Query query = reference;
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    FirebaseRecyclerOptions lobbyOptions = new FirebaseRecyclerOptions.Builder<Lobby>().setQuery(query, Lobby.class).build();
    mLobbyAdapter = new FirebaseRecyclerAdapter<Lobby, LobbyViewHolder>(lobbyOptions) {
        @Override
        protected void onBindViewHolder(@NonNull LobbyViewHolder holder, int position, @NonNull Lobby model) {
            holder.bindLobby(model);
            //here you associate the holder views with the model attributes
        }
        @Override
        public LobbyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.your_layout_file, parent, false);
        return new LobbyViewHolder(view);
        }
    };
}

相关内容

  • 没有找到相关文章

最新更新