我不知道如何使用firestore使用stickyheader处理recyclerview

时间:2019-11-25 16:16:23

标签: android android-recyclerview

希望提出申请。我是新手(大约2个月),而且我英语说起来很不舒服。

我想用粘性标题处理recyclerview,但是我不知道该怎么办。 TT

这是我的主要活动:

    mDatas = new ArrayList<>();
    mAdapter = new Today_Way_Adapter(mDatas, context);
    recyclerView = (RecyclerView) findViewById(R.id.rv_today_way_m3);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);


    Query query = mStore.collection(FirebaseID.post).orderBy(FirebaseID.goodcounting, Query.Direction.DESCENDING).limit(11);
    query.get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        mDatas = new ArrayList<>();
                        for (DocumentSnapshot snapshot : task.getResult()) {
                            Map<String, Object> shot = snapshot.getData();
                            String documentID = String.valueOf(snapshot.get(FirebaseID.documentID));
                            String words1 = String.valueOf(snapshot.get(FirebaseID.words1));
                            String words2 = String.valueOf(snapshot.get(FirebaseID.words2));
                            String words3 = String.valueOf(snapshot.get(FirebaseID.words3));
                            String words4 = String.valueOf(snapshot.get(FirebaseID.words4));
                            String words5 = String.valueOf(snapshot.get(FirebaseID.words5));
                            String contents = String.valueOf(snapshot.get(FirebaseID.contents));
                            String title = String.valueOf(snapshot.get(FirebaseID.title));
                            String forfindwhere = String.valueOf(snapshot.get(FirebaseID.forfindwhere));
                            String goodcounting = String.valueOf(snapshot.get(FirebaseID.goodcounting));
                            String commentcounting = String.valueOf(snapshot.get(FirebaseID.commentcounting));
                            String btn_good = String.valueOf(snapshot.get(forfindwhere + mAuth.getCurrentUser().getUid() + "good"));
                            String timestamp = String.valueOf(snapshot.get("timestamp"));

                            Today_Way_Post data = new Today_Way_Post(documentID, words1, words2, words3, contents, goodcounting, commentcounting, timestamp, forfindwhere, btn_good, );
                            mDatas.add(data);
                        }
                        mAdapter = new Today_Way_Adapter(mDatas, context);
                        recyclerView.setAdapter(mAdapter);
                    }
                }
            });

还有我的适配器:

public Today_Way_Adapter(List<Today_Way_Post> datas, Context context) {
    this.datas = datas;
    this.context = context;
}

@NonNull
@Override
public Today_Way_ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new Today_Way_Adapter.Today_Way_ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_today_way, parent, false));
}

@Override
public void onBindViewHolder(@NonNull Today_Way_ViewHolder holder, int position) {
    Today_Way_Post data = datas.get(position);
    Glide.with(holder.itemView)
            .load(datas.get(position).getBtn_good())
            .into(holder.btn_good);
    Glide.with(holder.itemView)
            .load(datas.get(position).getProfileimage())
            .into(holder.profile_image);
    holder.tvcoontents.setText(data.getContents());
    holder.words1.setText(data.getWords1());
    holder.words2_today_way.setText(data.getWords2());
    holder.words3_today_way.setText(data.getWords3());
    holder.goodcount.setText(data.getGoodcounting());
    holder.commentcount.setText(data.getCommentcounting());
    holder.name.setText(data.getName());
    holder.forfindwhere.setText(data.getForfindwhere());
    String ts1 = datas.get(position-1).getTimestamp();
    String ts2 = datas.get(position).getTimestamp();

}

@Override
public int getItemCount() {
    return datas.size();
}


public static class HeaderViewholder extends RecyclerView.ViewHolder {
    TextView textView;

    HeaderViewholder(View itemView) {
        super(itemView);
        textView = itemView.findViewById(R.id.text_view);
    }
}


public class Today_Way_ViewHolder extends RecyclerView.ViewHolder {

    TextView tvcoontents, words1, words2_today_way, words3_today_way, goodcount, commentcount, name, header, forfindwhere;

    ImageView profile_image, btn_good;

    public Today_Way_ViewHolder(@NonNull View itemView) {
        super(itemView);

        this.profile_image = itemView.findViewById(R.id.image_profile_today_way);
        this.tvcoontents = itemView.findViewById(R.id.tv_contents_today_way);
        this.words1 = itemView.findViewById(R.id.words1_today_way);
        this.words2_today_way = itemView.findViewById(R.id.words2_today_way);
        this.words3_today_way = itemView.findViewById(R.id.words3_today_way);
        this.goodcount = itemView.findViewById(R.id.goodcount_today_way);
        this.commentcount = itemView.findViewById(R.id.commentcount_today_way);
        this.name = itemView.findViewById(R.id.tv_name_today_way);
        this.btn_good = itemView.findViewById(R.id.btn_good_today_way);
        this.header = itemView.findViewById(R.id.tv_header);
    }
}

}

最后是TT。在4天的白天和晚上,我删除并编辑了代码,并将其添加到了代码中。

我的编码技能是空的,所以我的问题可能令人困惑。

但是,如果可能,您能帮我吗?

我想一起应用recyclerview来响应滚动,如果还有时间,可以吗? 例如:向下滚动淡出;向上滚动淡入。

0 个答案:

没有答案