Написал метод приема данных из firebase и viewholder,adapter для этого метода.
Вот активити
public class HomeActivity extends AppCompatActivity {
private ImageView button_cart,image_but_saat;
private TextView textname_hame;
private DatabaseReference prodReference;
private RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
recyclerView=(RecyclerView) findViewById(R.id.recycle_product);
prodReference= FirebaseDatabase.getInstance().getReference().child("Products");
button_cart=(ImageView) findViewById(R.id.button_cart);
image_but_saat=(ImageView) findViewById(R.id.image_but_saat);
layoutManager=new LinearLayoutManager(this);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
textname_hame=(TextView) findViewById(R.id.textname_hame);
textname_hame.setText(Prevalent.currentOnlineUser.getName());
Picasso.get().load(Prevalent.currentOnlineUser.getImage()).into(image_but_saat);
image_but_saat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent setIntent=new Intent(HomeActivity.this, UseraccActivity.class);
startActivity(setIntent);
}
});
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Products>options=new FirebaseRecyclerOptions.Builder<Products>()
.setQuery(prodReference,Products.class).build();
FirebaseRecyclerAdapter<Products, ProductHolder>adapter=new FirebaseRecyclerAdapter<Products, ProductHolder>(options
) {
@Override
protected void onBindViewHolder(@NonNull @androidx.annotation.NonNull ProductHolder holder, int position, @NonNull @androidx.annotation.NonNull Products model) {
ProductHolder.txtProductName.setText(model.getProdname());
ProductHolder.txtProductopisanie.setText(model.getDescription());
ProductHolder.txtProductPrice.setText(model.getPrice());
Picasso.get().load(model.getImage()).into(holder.product_image);
}
@Override
public ProductHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items_layout,parent,false);
ProductHolder holder=new ProductHolder(view);
return null;
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
}
}
Вот ProductHolder
public class ProductHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtProductName,txtProductopisanie,txtProductPrice;
public ImageView product_image;
public ItemClickListner listner;
public ProductHolder(View itemView){
super(itemView);
product_image=itemView.findViewById(R.id.product_image);
txtProductName=itemView.findViewById(R.id.produt_name_text);
txtProductopisanie=itemView.findViewById(R.id.product_opisnie);
txtProductPrice=itemView.findViewById(R.id.product_surprice);
}
public void setItemClickListner(ItemClickListner listner){this.listner=listner;}
@Override
public void onClick(View view){
listner.onClick(view,getAdapterPosition(),false);
}
}
Адаптер
public class Products {
private String prodname,description,image,category,prodid,date,time,price;
public Products(){
}
public Products(String prodname, String description, String image, String category, String prodid, String date, String time,String price) {
this.prodname = prodname;
this.description = description;
this.image = image;
this.category = category;
this.prodid = prodid;
this.date = date;
this.time = time;
this.price=price;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getProdname() {
return prodname;
}
public void setProdname(String prodname) {
this.prodname = prodname;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getProdid() {
return prodid;
}
public void setProdid(String prodid) {
this.prodid = prodid;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
Ошибки в основном активити:Type parameter 'door.one.marketplace.ViewHolders.ProductHolder' is not within its bound; should extend 'android.support.v7.widget.RecyclerView.ViewHolder":67
Type parameter 'door.one.marketplace.ViewHolders.ProductHolder' is not within its bound; should extend 'android.support.v7.widget.RecyclerView.ViewHolder':67
Non-static field 'txtProductName' cannot be referenced from a static context:71
Non-static field 'txtProductopisanie' cannot be referenced from a static context:73
Non-static field 'txtProductPrice' cannot be referenced from a static context:74
setAdapter(androidx.recyclerview.widget.RecyclerView.Adapter)' in 'androidx.recyclerview.widget.RecyclerView' cannot be applied to '(com.firebase.ui.database FirebaseRecyclerAdapter< door.one.marketplace.Products,door.one.ViewHolders.ProductHolder
Почему выходят такие ошибки если я там уже прописал какие данные брать и куда вставлять,буду благодарен за помощь.