使Firebase Recycler可扩展(自定义适配器)

时间:2017-01-21 23:37:04

标签: android firebase android-recyclerview firebase-realtime-database firebaseui

我已经尝试了几天来实现点击项目(填充了firebase数据)的选项扩展,就像下面的lib 1lib 2允许的那样,我也尝试过将以下“本机”解决方案添加到onBindViewHolder方法,但没有任何效果,因为当我创建扩展FirebaseRecyclerAdapter的自定义适配器时,我似乎无法访问此方法

final boolean isExpanded = position==mExpandedPosition;
holder.details.setVisibility(isExpanded?View.VISIBLE:View.GONE);
holder.itemView.setActivated(isExpanded);
holder.itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mExpandedPosition = isExpanded ? -1:position;
        TransitionManager.beginDelayedTransition(recyclerView);
        notifyDataSetChanged();
    }
});

这是

的当前代码
    private RecyclerView mPostRV;
private FirebaseRecyclerAdapter<Post, PostViewHolder> mPostAdapter;
private DatabaseReference mPostRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_food_main);

    initialiseScreen();

}


private void initialiseScreen() {
    mPostRV = (RecyclerView) findViewById(R.id.post_rv);
    mPostRV.setLayoutManager(new LinearLayoutManager(FoodMain.this));
    mPostRef = FirebaseDatabase.getInstance().getReference(Constants.FOODS);
    setupAdapter();
    mPostRV.setAdapter(mPostAdapter);
}

private void setupAdapter() {

    mPostAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(
            Post.class,
            R.layout.item_layout_post,
            PostViewHolder.class,
            mPostRef
    ) {

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

            StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(model.getImageUrl());
            Glide.with(FoodMain.this)
                    .using(new FirebaseImageLoader())
                    .load(storageReference)
                    .into(viewHolder.postIV);

            viewHolder.setName(model.getName());
            viewHolder.setPhone(model.getPhone());



        }
    };


}

由于

0 个答案:

没有答案