I need to retrieve user request requests from the Firebase in the RecyclerView so that they organize those requests in the list without overwriting the other. For now my list is static.
Each user has an id in the DB and each request has tbm.
Adapter
public class AdapterSolicitacoes extends RecyclerView.Adapter <AdapterSolicitacoes.MyViewHolder> {
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView bairro;
TextView endereco;
TextView data;
public MyViewHolder(View itemView) {
super(itemView);
bairro = itemView.findViewById(R.id.tv_bairro);
endereco = itemView.findViewById(R.id.tv_endereco);
data = itemView.findViewById(R.id.tv_data);
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLista = LayoutInflater.from(parent.getContext())
.inflate(R.layout.adapter_lista_solicitacao, parent, false);
return new MyViewHolder(itemLista);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.bairro.setText("ITAJAI");
holder.endereco.setText("Rua JOAO DE BARRO, 222.");
holder.data.setText("27 Abr 18");
}
@Override
public int getItemCount() {
return 10;
}
}
Fragment
public class SolicRecebidaFragment extends Fragment {
private RecyclerView recyclerViewListaSolicitacao;
private DatabaseReference referencia ;
public SolicRecebidaFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_solicitacao_recebida, container, false);
//Config.Inciais
recyclerViewListaSolicitacao = view.findViewById(R.id.recyclerView_ListaSolicitacao);
//Config.Adapter
AdapterSolicitacoes adapter = new AdapterSolicitacoes();
//Config.RecyclerView
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerViewListaSolicitacao.setLayoutManager( layoutManager);
recyclerViewListaSolicitacao.setHasFixedSize(true);
recyclerViewListaSolicitacao.setAdapter( adapter );
//Recupera endereço do nó usuarios
referencia = ConfiguracaoFirebase.getFirebaseDataBase().child("usuarios");
referencia.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.i("DADOS FIREBASE: ", dataSnapshot.getValue().toString());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return view;
}
}