Надеюсь, у вас все хорошо, я работаю с FirebaseDataBase, и у меня возникают проблемы с Castear данных, поступающих с каждого из узлов, и отображением их в Recyclearview рядом с CardView, я работаю с адаптером.
Я прикрепляю изображение того, как структура и узлы состоят из того, где мне нужно получить их информацию.
изображение структуры узлов
Context context;
List<ActiveAchievements> categorieslist;
public AssetsAdapter(Context context, List<ActiveAchievements> contactList) {
this.context = context;
this.categorieslist = contactList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card_view_assents, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder Viewholder, final int position) {
final ActiveAchievements achievements = categorieslist.get(position);
Viewholder.title.setText(achievements.getTitulo());
Viewholder.descripcion.setText(achievements.getDescripcion());
Viewholder.conins.setText(achievements.getQaploins());
Viewholder.timer.setText(achievements.getTiempoLimite());
/**
Glide.with(context)
.load(categoriesP.getLogo())
.apply(new RequestOptions().override(200, 200))
.error(Glide.with(context).load(R.mipmap.ic_launcher))
.into(Viewholder.imgLogo);**/
}
@Override
public int getItemCount() {
return categorieslist.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView imgLogo;
public TextView title,conins,descripcion,timer;
public ProgressBar progress;
public ViewHolder(View itemView) {
super(itemView);
//imgLogo = itemView.findViewById(R.id.imgLogo);
title = itemView.findViewById(R.id.title_text);
conins = itemView.findViewById(R.id.title_text);
descripcion = itemView.findViewById(R.id.title_text);
timer = itemView.findViewById(R.id.conins_text);
progress = itemView.findViewById(R.id.progress_assets);
}
}
}
private RecyclerView mRecyclerView;
private List<ActiveAchievements> list;
AssetsAdapter adapter;
/** FIREBASE **/
private FirebaseAuth firebaseAuth;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mLogrosActivosDatabaseReference;
private DatabaseReference mqaploinsActivosDatabaseReference;
private DatabaseReference msocialActivosDatabaseReference;
private DatabaseReference mverificadoActivosDatabaseReference;
private DatabaseReference mxOverActivosDatabaseReference;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.item_recyclerview, container, false);
// Referencias
mRecyclerView = view.findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
/**FIREBASE DATA**/
firebaseAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
//mLogrosActivosDatabaseReference = mFirebaseDatabase.getReference().child("logrosActivos");
mLogrosActivosDatabaseReference = FirebaseDatabase.getInstance().getReference().child("logrosActivos");
mqaploinsActivosDatabaseReference = FirebaseDatabase.getInstance().getReference().child("qaploins");
msocialActivosDatabaseReference = FirebaseDatabase.getInstance().getReference().child("social");
mverificadoActivosDatabaseReference = FirebaseDatabase.getInstance().getReference().child("verificado");
mxOverActivosDatabaseReference = FirebaseDatabase.getInstance().getReference().child("xOver");
//mLogrosActivosDatabaseReference.keepSynced(true);
mLogrosActivosDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
list = new ArrayList<ActiveAchievements>();
if (dataSnapshot.exists()){
for(DataSnapshot dataSnapshot1 :dataSnapshot.getChildren())
{
ActiveAchievements p = dataSnapshot1.getValue(ActiveAchievements.class);
ActiveAchievements fire = new ActiveAchievements();
String titulo = p.getTitulo();
String descripcion = p.getDescripcion();
String pageLink = p.getPageLink();
String photoUrl = p.getPhotoUrl();
String qaploins = p.getQaploins();
String tiempoLimite = p.getTiempoLimite();
String tipoLogro = p.getTipoLogro();
int totalPuntos = p.getTotalPuntos();
list.add(fire);
}
adapter = new AssetsAdapter(getActivity(),list);
mRecyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(getActivity(), "Opsss.... Something is wrong", Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
```ActiveAchievements
public class ActiveAchievements {
private String descripcion;
private String pageLink;
private String photoUrl;
private String qaploins;
private String tiempoLimite;
private String tipoLogro;
private String titulo;
private int totalPuntos;
public ActiveAchievements(String descripcion, String pageLink, String photoUrl, String qaploins, String tiempoLimite, String tipoLogro, String titulo, int totalPuntos) {
this.descripcion = descripcion;
this.pageLink = pageLink;
this.photoUrl = photoUrl;
this.qaploins = qaploins;
this.tiempoLimite = tiempoLimite;
this.tipoLogro = tipoLogro;
this.titulo = titulo;
this.totalPuntos = totalPuntos;
}
public ActiveAchievements() {
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public String getPageLink() {
return pageLink;
}
public void setPageLink(String pageLink) {
this.pageLink = pageLink;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getQaploins() {
return qaploins;
}
public void setQaploins(String qaploins) {
this.qaploins = qaploins;
}
public String getTiempoLimite() {
return tiempoLimite;
}
public void setTiempoLimite(String tiempoLimite) {
this.tiempoLimite = tiempoLimite;
}
public String getTipoLogro() {
return tipoLogro;
}
public void setTipoLogro(String tipoLogro) {
this.tipoLogro = tipoLogro;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public int getTotalPuntos() {
return totalPuntos;
}
public void setTotalPuntos(int totalPuntos) {
this.totalPuntos = totalPuntos;
}
@Override
public String toString() {
return "ActiveAchievements{" +
"descripcion='" + descripcion + '\'' +
", pageLink='" + pageLink + '\'' +
", photoUrl='" + photoUrl + '\'' +
", qaploins='" + qaploins + '\'' +
", tiempoLimite='" + tiempoLimite + '\'' +
", tipoLogro='" + tipoLogro + '\'' +
", titulo='" + titulo + '\'' +
", totalPuntos=" + totalPuntos +
'}';
}
}