Production Application, how to retrieve data from firebase in recyclerview?

0

I'm developing an application and I'm in the employee listing and production part ("this listing in a single line in the recyclerview referring to the employee") but I'm having problems because I do not know how to bring the employee and the production because are two different node wanted to know how do I get the employee node and its production that is in the node production, I followed my code and my realtime in the firebase.

THIS IS MY REALTIME ON FIREBASE

NOWMYJAVACLASSCODE.

ClassOfficer

publicclassFunctionalimplementsParcelable{

privateStringidFuncionario;privateStringfuncaoFuncionario;privateStringnomeFuncionario;publicFuncionario(){}publicFuncionario(StringidFuncionario,StringfuncaoFuncionario,StringnomeFuncionario){this.idFuncionario=idFuncionario;this.funcaoFuncionario=funcaoFuncionario;this.nomeFuncionario=nomeFuncionario;}publicStringgetIdFuncionario(){returnidFuncionario;}publicvoidsetIdFuncionario(StringidFuncionario){this.idFuncionario=idFuncionario;}publicStringgetFuncaoFuncionario(){returnfuncaoFuncionario;}publicvoidsetFuncaoFuncionario(StringfuncaoFuncionario){this.funcaoFuncionario=funcaoFuncionario;}publicStringgetNomeFuncionario(){returnnomeFuncionario;}publicvoidsetNomeFuncionario(StringnomeFuncionario){this.nomeFuncionario=nomeFuncionario;}publicvoidsalvar(){if(!TextUtils.isEmpty(getNomeFuncionario())){Funcionariofunc=newFuncionario(getIdFuncionario(),getFuncaoFuncionario(),getNomeFuncionario());DatabaseReferencereferenciaFirebase=ConfiguracaoFirebase.getFirebaseFuncionario();Stringid=referenciaFirebase.push().getKey();func.setIdFuncionario(id);referenciaFirebase.child(func.getIdFuncionario()).setValue(func);}else{}}

ProductionClass

publicclassProducao{

privateStringidProducao;privateStringnumProducao;privateStringtipoProducao;privateStringmetaProducao;privateStringtempoProducao;privateStringhoraDataProducao;privateStringtotalProducao;publicProducao(StringidProducao,StringnumProducao,StringhoraDataProducao,StringmetaProducao,StringtempoProducao,StringtipoProducao,StringtotalProducao){this.idProducao=idProducao;this.numProducao=numProducao;this.horaDataProducao=horaDataProducao;this.metaProducao=metaProducao;this.tempoProducao=tempoProducao;this.tipoProducao=tipoProducao;this.totalProducao=totalProducao;}publicProducao(){}publicProducao(StringidProducao,StringnumProducao,StringhoraDataProducao,StringmetaProducao,StringtempoProducao,StringtotalProducao){}publicStringgetIdProducao(){returnidProducao;}publicvoidsetIdProducao(StringidProducao){this.idProducao=idProducao;}publicStringgetNumProducao(){returnnumProducao;}publicvoidsetNumProducao(StringnumProducao){this.numProducao=numProducao;}publicStringgetTipoProducao(){returntipoProducao;}publicvoidsetTipoProducao(StringtipoProducao){this.tipoProducao=tipoProducao;}publicStringgetMetaProducao(){returnmetaProducao;}publicvoidsetMetaProducao(StringmetaProducao){this.metaProducao=metaProducao;}publicStringgetTempoProducao(){returntempoProducao;}publicvoidsetTempoProducao(StringtempoProducao){this.tempoProducao=tempoProducao;}publicStringgetHoraDataProducao(){returnhoraDataProducao;}publicvoidsetHoraDataProducao(StringhoraDataProducao){this.horaDataProducao=horaDataProducao;}publicStringgetTotalProducao(){returntotalProducao;}publicvoidsetTotalProducao(StringtotalProducao){this.totalProducao=totalProducao;}publicvoidsalvar(){Producaoproducao=newProducao(getIdProducao(),getNumProducao(),getHoraDataProducao(),getMetaProducao(),getTempoProducao(),getTipoProducao(),getTotalProducao());DatabaseReferencerefFirebase=ConfiguracaoFirebase.getFirebaseProducao();Stringid=refFirebase.push().getKey();producao.setIdProducao(id);setIdProducao(producao.getIdProducao());refFirebase.child(producao.getIdProducao()).setValue(producao);}

}

MyAdapterclass

publicclassMyAdapterextendsRecyclerView.Adapter{

privateContextcontext;privateList<Funcionario>f;privateList<Producao>p;publicMyAdapter(Contextcontext,List<Funcionario>f){this.context=context;this.f=f;notifyDataSetChanged();}publicMyAdapter(Contextcontext){this.context=context;}publicMyAdaptersetFuncList(List<Producao>producaos){this.p=producaos;notifyDataSetChanged();returnnull;}@OverridepublicViewHolderonCreateViewHolder(ViewGroupparent,intviewType){Viewv=LayoutInflater.from(context).inflate(R.layout.recycler_view_list_item,parent,false);returnnewViewHolder(v);}@OverridepublicvoidonBindViewHolder(ViewHolderholder,@SuppressLint("RecyclerView") final int position) {

    holder.textFuncao.setText(f.get(position).getFuncaoFuncionario());
    holder.textNome.setText(f.get(position).getNomeFuncionario());



}

@Override
public int getItemCount() {
    return f.size();
}


class ViewHolder extends RecyclerView.ViewHolder {
    private ImageView ivFuncao;
    private TextView textFuncao;
    private TextView textNome;
    private TextView textRefProd;
    private TextView textTamProducao;
    private TextView textProcesso;
    private TextView textMeta;
    private TextView textCronometro;
    private TextView textDataHora;
    private TextView textTotalDia;

    ViewHolder(final View itemView) {

        super(itemView);

        ivFuncao = (ImageView) itemView.findViewById(R.id.iv_funcao);
        textFuncao = (TextView) itemView.findViewById(R.id.tv_funcao);
        textNome = (TextView) itemView.findViewById(R.id.tv_nome);
        textRefProd = (TextView) itemView.findViewById(R.id.tv_referencia_produto);
        textTamProducao = (TextView) itemView.findViewById(R.id.tv_produto_tam_producao);
        textProcesso = (TextView) itemView.findViewById(R.id.tv_processo);
        textMeta = (TextView) itemView.findViewById(R.id.tv_meta);
        textCronometro = (TextView) itemView.findViewById(R.id.tv_cronometro_tempo);
        textDataHora = (TextView) itemView.findViewById(R.id.tv_data_hora_dia);
        textTotalDia = (TextView) itemView.findViewById(R.id.tv_total_produzido);
    }
}

}

I'm using fragment so the snippet where I'm looking for the official in the FragmentA class

@Override     public void onStart () {         super.onStart ();         databaseFuncionario.addValueEventListener (new ValueEventListener () {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            mList.clear();

            for(DataSnapshot funcioSnapshot : dataSnapshot.getChildren()) {
                dataSnapshot.child(Constants.DATABASE_PATH_PRODUCAO);
                Funcionario f = funcioSnapshot.getValue(Funcionario.class);
                mList.add(f);
            }
            recyclerViewFuncionario = new RecyclerView(getContext());
            recyclerViewFuncionario = (RecyclerView) getView().findViewById(R.id.recycler_view);
            MyAdapter adapter = new MyAdapter(getContext(), mList);
            recyclerViewFuncionario.addOnItemTouchListener(new RecyclerViewTouchListener(getActivity(), recyclerViewFuncionario, FragmentA.this));
            recyclerViewFuncionario.setHasFixedSize(true);
            LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
            recyclerViewFuncionario.setLayoutManager(layoutManager);
            recyclerViewFuncionario.setAdapter(adapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }

    });
}

}

If any generous heart can help me, I thank you, remembering I can not list the employee in the recyclerview and the production by his id.

    
asked by anonymous 25.11.2017 / 12:43

1 answer

0

You have to use a addValueEventListener for each node you access, in this case, one for the employee (which is done) and another for the production.

PS: Add another 4 spaces at the beginning of all the lines of code so that the stack overflow recognizes it as a single block of code.

    
19.01.2018 / 16:43