I want to send variables from a Fragment to an Adapter ...
Here are the values of the Fragment that I want to send and some other code. The values I want to send are Country, City, Company Type, CompanyUser and Logo.
País = getArguments().getString("País");
Ciudad = getArguments().getString("Ciudad");
TipodeEmpresa = getArguments().getString("TipodeEmpresa");
EmpresaUser = getArguments().getString("EmpresaUser");
Logo = getArguments().getString("Logo");
//ESTO ES PARA EL RecyclerView
recyclerTipoAtencion.setLayoutManager(new LinearLayoutManager(getActivity()));
usuarios = new ArrayList<>();
FirebaseDatabase database = FirebaseDatabase.getInstance();
adapterTipoAtencion = new AdapterTipoAtencion(usuarios);
recyclerTipoAtencion.setAdapter(adapterTipoAtencion);
And this is my Complete Adapter ... However, I need to send the data to the "public static class TypeAntertainmentViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener", because if I send them to the Adapter in general, it does not recognize the variables in the TypeAntertainmentViewHolder ... I need to be able to use the Fragment variables within the OnClick of my Adapter, at the end of the code.
public class AdapterTipoAtencion extends RecyclerView.Adapter<AdapterTipoAtencion.TipoAtencionViewHolder> {
List<Usuario> usuarios;
private String tap1, tap2, retap1, retap2;
private TextView textviewtipoatencion1, textviewtipoatencion2;
private View viewtipoatencion1, viewtipoatencion2;
public AdapterTipoAtencion(List<Usuario> usuarios) { this.usuarios = usuarios; }
@Override
public TipoAtencionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).
inflate(R.layout.row_recycler_tipoatencion, parent, false);
TipoAtencionViewHolder holder = new TipoAtencionViewHolder(v);
textviewtipoatencion1 = v.findViewById(R.id.textview_tipoatencion1);
textviewtipoatencion2 = v.findViewById(R.id.textview_tipoatencion2);
viewtipoatencion1 = v.findViewById(R.id.view_tipoatencion1);
viewtipoatencion2 = v.findViewById(R.id.view_tipoatencion2);
return holder;
}
@Override
public void onBindViewHolder(TipoAtencionViewHolder holder, int position) {
Usuario usuario = usuarios.get(position);
tap1 = usuario.getTipoAtencion1();
tap2 = usuario.getTipoAtencion2();
if (tap1 == null) {
textviewtipoatencion1.setVisibility(View.INVISIBLE);
viewtipoatencion1.setVisibility(View.INVISIBLE);
} else {
holder.textviewtipoatencion1.setText(usuario.getTipoAtencion1());
retap1 = textviewtipoatencion1.getText().toString();
}
if (tap2 == null) {
textviewtipoatencion2.setVisibility(View.INVISIBLE);
viewtipoatencion2.setVisibility(View.INVISIBLE);
} else {
holder.textviewtipoatencion2.setText(usuario.getTipoAtencion2());
retap2 = textviewtipoatencion2.getText().toString();
}
holder.setOnClickListeners();
}
@Override
public int getItemCount() { return usuarios.size(); }
public static class TipoAtencionViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private Context context;
private TextView textviewtipoatencion1, textviewtipoatencion2;
private View viewtipoatencion1, viewtipoatencion2;
private Button btnDetails, btnEditHeader;
public TipoAtencionViewHolder(View v) {
super(v);
context = v.getContext();
textviewtipoatencion1 = v.findViewById(R.id.textview_tipoatencion1);
textviewtipoatencion2 = v.findViewById(R.id.textview_tipoatencion2);
viewtipoatencion1 = v.findViewById(R.id.view_tipoatencion1);
viewtipoatencion2 = v.findViewById(R.id.view_tipoatencion2);
btnDetails = v.findViewById(R.id.btnDetails);
btnEditHeader = v.findViewById(R.id.btnEditHeader);
}
void setOnClickListeners(){
textviewtipoatencion1.setOnClickListener(this);
textviewtipoatencion2.setOnClickListener(this);
btnDetails.setOnClickListener(this);
btnEditHeader.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.textview_tipoatencion1:
String txttap1 = textviewtipoatencion1.getText().toString();
Toast.makeText(context, "Tipo de atención: " + txttap1, Toast.LENGTH_SHORT).show();
break;
case R.id.textview_tipoatencion2:
String txttap2 = textviewtipoatencion2.getText().toString();
Toast.makeText(context, "Tipo de atención: " + txttap2, Toast.LENGTH_SHORT).show();
break;
}
}
}
}
I hope you can help me ... Thank you very much for everything!