Как я хочу добавить функцию setOnClickListener в мой код и передать информацию, которая продолжается в записи по клику, в другое действие. Я не знаю, как это сделать. Я рад принять помощь. спасибо.
Я приложил две части кода, с которыми я работаю: Это мой класс adCake.java:
package com.lee.app1_new;
public class adCake {
private String image;
private String name;
private String ingredients;
private String preparation;
public adCake(String image, String name, String ingredients, String preparation) {
this.image = image;
this.name = name;
this.ingredients = ingredients;
this.preparation = preparation;
}
public void setImage(String image) {
this.image = image;
}
public String getImage() {
return image;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
public void setPreparation(String preparation) {
this.preparation = preparation;
}
public String getIngredients() {
return ingredients;
}
public String getPreparation() {
return preparation;
}
public adCake(){
super();
}
}
Это мой класс recycle_recipe.java:
package com.lee.app1_new;
import android.content.Context;
import android.media.Image;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
public class recycle_recipe extends AppCompatActivity {
private RecyclerView mRlist;
private DatabaseReference mDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycle_recipe);
mDatabase= FirebaseDatabase.getInstance().getReference().child("cake");
mDatabase.keepSynced(true);
mRlist=findViewById(R.id.recycle);
// mRlist.setHasFixedSize(true);
mRlist.setLayoutManager(new LinearLayoutManager(this));
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<adCake,adCakeViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<adCake,adCakeViewHolder>
(adCake.class,R.layout.recip_card,adCakeViewHolder.class,mDatabase){
@Override
protected void populateViewHolder(adCakeViewHolder viewHolder,adCake model,int position)
{
viewHolder.setName(model.getName());
viewHolder.setIng(model.getIngredients());
viewHolder.setPrep(model.getPreparation());
viewHolder.setImg(getApplicationContext(),model.getImage());
}
};
mRlist.setAdapter(firebaseRecyclerAdapter);
}
public static class adCakeViewHolder extends RecyclerView.ViewHolder{
View mView;
public adCakeViewHolder(@NonNull View itemView) {
super(itemView);
mView=itemView;
}
public void setName(String name)
{
TextView post_name=(TextView)mView.findViewById(R.id.name);
post_name.setText(name);
}
public void setIng(String ing)
{
TextView post_ing=(TextView)mView.findViewById(R.id.ingredients);
post_ing.setText(ing);
}
public void setPrep(String prep)
{
TextView post_prep=(TextView)mView.findViewById(R.id.preparation);
post_prep.setText(prep);
}
public void setImg(Context ctx, String img)
{
ImageView post_img=(ImageView)mView.findViewById(R.id.image);
Picasso.with(ctx).load(img).into(post_img);
}
}
}