在recyclerview的顶部添加新图像

时间:2017-02-28 15:33:59

标签: android firebase firebase-realtime-database firebaseui

我正试图在顶部显示新的更新。我正在使用firebase和recyclerview。

 @Override
    protected void onStart() {
        super.onStart();
        FirebaseRecyclerAdapter<Feed,FeedViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Feed, FeedViewHolder>(
                Feed.class,R.layout.news_feed_row,FeedViewHolder.class,mDatabase
        ) {
            @Override
            protected void populateViewHolder(FeedViewHolder viewHolder, Feed model, int position) {

               viewHolder.setdesc(model.getDesc());
                viewHolder.setimage(getApplicationContext(),model.getImage());
            }
        };
        mNews_Feed_list.setAdapter(firebaseRecyclerAdapter);

    }
    public static class FeedViewHolder extends RecyclerView.ViewHolder{

         View mView;
        public FeedViewHolder(View itemView) {
            super(itemView);
            mView = itemView;

        }

        public void setdesc(String desc){
            TextView post_desc_value = (TextView) mView.findViewById(R.id.post_desc_card_view);
            post_desc_value.setText(desc);

        }
        public void setimage(final Context ctx, final String image){
            final ImageView post_image = (ImageView) mView.findViewById(R.id.post_image_card_view);
            Glide.with(ctx).load(image).diskCacheStrategy(DiskCacheStrategy.ALL).into(post_image);
        }
    }

1 个答案:

答案 0 :(得分:0)

将此方法添加到适配器并调用它以将新项目添加到回收站视图

public void addItem(Feed model){
    <your list name>.add(0, model);
    notifyItemInserted(0);
    mRecyclerView.smoothScrollToPosition(0);
}