I have a recyclerview. Once user clicked on any item of recyclerview item it should open a new fragment. But I would like to pass a id with it like we send with intent using putExtra.
Below is my adapter onBindViewHolder method code -
public void onBindViewHolder(@NonNull DashboardViewHolder holder, int position) {
final Dashboard product = dashboardList.get(position);
//loading the image
Glide.with(mCtx)
.load(product.getImage())
.into(holder.imageView);
holder.rate.setText(product.getRate());
holder.name.setText(product.getName());
holder.city.setText(product.getCity());
//holder.id.setText(String.valueOf(product.getId()));
holder.boatList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mCtx, ""+String.valueOf(product.getId()), Toast.LENGTH_SHORT).show();
//Intent intent = new Intent(mCtx, AddNewBoatFragment.class);
//intent.putExtra("boat_id", product.getId());
//intent.putExtra("owner_id", product.getOwner_id());
//mCtx.startActivity(intent);
//getSupportFragmentManager().beginTransaction().replace(R.id.dahsboard_fragment,
//new MyBoatFragment()).commit();
Fragment fragment = new AddNewBoatFragment();
FragmentManager fm = ((AppCompatActivity)mCtx).getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.dahsboard_fragment, fragment);
ft.commit();
}
});
}
Below is my class -
public Dashboard(int id, int owner_id, String image, String rate, String name, String city){
this.id = id;
this.owner_id = owner_id;
this.image = image;
this.rate = rate;
this.name = name;
this.city = city;
}
public int getId(){ return id; }
public String getImage() {
return image;
}
public String getRate() { return rate; }
public String getName(){
return name;
}
public String getCity() { return city; }
public int getOwner_id() { return owner_id; }