firebaserecycleradapter最后给列表顶部的旧帖子和新帖子,我需要顶部的新帖子,我怎么能得到它?

时间:2018-03-05 05:41:38

标签: android firebase user-interface firebase-realtime-database android-recyclerview

这是我在firebase中从RecyclerView数据库获取帖子的代码,

 @Override
    protected void onStart() {
        super.onStart();
        FirebaseRecyclerAdapter<Post,PostViewFolder> PSVF=new FirebaseRecyclerAdapter<Post, PostViewFolder>(
                Post.class,
                R.layout.singlepostitem,
                PostViewFolder.class,
                mDatabse) {

            @Override
            protected void populateViewHolder(PostViewFolder viewHolder, Post model, int position) {

                viewHolder.setTitle(model.getPosttitle());
                viewHolder.setDesc(model.getPostdesc());
                viewHolder.setImage(getApplicationContext(),model.getPostimage());

                final String post_key=getRef(position).getKey().toString();

                viewHolder.mview.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(PostList.this,Singlepost.class);
                        intent.putExtra("post_id",post_key);
                        startActivity(intent);


                    }
                });

            }
        };

        mpostlist.setAdapter(PSVF);        
    }


    public static class PostViewFolder extends RecyclerView.ViewHolder{

        View mview;
        public PostViewFolder(View itemView) {
            super(itemView);
            mview=itemView;
        }
        public void setTitle(String posttitle){
            TextView post_title=(TextView) mview.findViewById(R.id.posttitle);
            post_title.setText(posttitle);

        }

        public void setDesc(String postdesc){
            TextView post_desc=(TextView) mview.findViewById(R.id.postdescription);
            post_desc.setText(postdesc);
        }
        public void setImage(Context ctx, String postimage){

            ImageView post_image=(ImageView) mview.findViewById(R.id.postimage);

            Picasso.with(ctx).load(postimage).into(post_image);
        }
    }

0 个答案:

没有答案