我試圖在兩種活動中重用Firebase適配器,並根據兩種活動使用不同的onClick偵聽器行爲。針對同一Firebase適配器的不同OnClickListener
下面是代碼:
public class ProductListAdapter {
private Query mQuery;
private Context mContext;
private FirebaseRecyclerAdapter<Product,ProductViewHolder> mAdapter;
public ProductListAdapter(Query query,Context context) {
mQuery = query;
mContext = context;
Update();
}
public void Update(){
mAdapter = new FirebaseRecyclerAdapter<Product, ProductViewHolder>(
Product.class,
R.layout.list_item_product,
ProductViewHolder.class,
mQuery
){
@Override
protected void populateViewHolder(ProductViewHolder viewHolder, Product model, int position) {
viewHolder.mProductTitle.setText(model.getProductTitle());
viewHolder.mProductDescription.setText(model.getProductDescription());
Product product = getItem(position);
viewHolder.bindView(product);
Picasso.with(mContext)
.load(model.getPhotoUrl())
.into(viewHolder.mThumbnail);
}
};
}
public RecyclerView.Adapter getAdapter(){
return mAdapter;
}
public static class ProductViewHolder extends RecyclerView.ViewHolder{
Product mProduct;
TextView mProductTitle;
TextView mProductDescription;
ImageView mThumbnail;
public ProductViewHolder(View itemView) {
super(itemView);
mProductTitle = (TextView) itemView.findViewById(R.id.product_title);
mProductDescription = (TextView) itemView.findViewById(R.id.product_description);
mThumbnail = (ImageView) itemView.findViewById(R.id.list_image);
}
public void bindView(Product product){
mProduct = product;
}
}
,這是調用活動,其調用firebaseadapter類的代碼,這個類是返回使用getAdapter方法和這是考慮到回收視圖適配器:
ProductListAdapter productListAdapter =
new ProductListAdapter(query,getActivity());
RecyclerView.Adapter adapter = productListAdapter.getAdapter();
mRecyclerView.setAdapter(adapter);
問題是什麼? – Shailesh
我想在其他活動中重用firebase適配器,但使用不同的onClickListener方法@Shailesh – Pheonix
其中是onClick()在您的代碼中? – Yazan