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

Asked

Viewed 203 times

0

Good morning guys I’m developing an app and I’m on the employee listing and production("this listing in a single line in recyclerview referring to the would work")but I’m in trouble because I don’t know how to bring the employee and the production because they are two different Ode wanted to know how I do to catch the employee and their production that is in Ode production, I followed my code and my Altime in firebase.

THIS IS MY REALTIME AT FIREBASE FUNCIONARIO E SUA PRODUÇÃO

NOW MY JAVA CLASS CODE.

Staff Class

public class Employee Installable Plans {

private String idFuncionario;
private String funcaoFuncionario;
private String nomeFuncionario;


public Funcionario() {
}


public Funcionario(String idFuncionario, String funcaoFuncionario,
                   String nomeFuncionario) {
    this.idFuncionario = idFuncionario;
    this.funcaoFuncionario = funcaoFuncionario;
    this.nomeFuncionario = nomeFuncionario;
}

public String getIdFuncionario() {
    return idFuncionario;
}

public void setIdFuncionario(String idFuncionario) {
    this.idFuncionario = idFuncionario;
}

public String getFuncaoFuncionario() {
    return funcaoFuncionario;
}

public void setFuncaoFuncionario(String funcaoFuncionario) {
    this.funcaoFuncionario = funcaoFuncionario;
}

public String getNomeFuncionario() {
    return nomeFuncionario;
}

public void setNomeFuncionario(String nomeFuncionario) {
    this.nomeFuncionario = nomeFuncionario;
}

public void salvar() {

    if( !TextUtils.isEmpty(getNomeFuncionario()) ) {
        Funcionario func = new Funcionario(getIdFuncionario(), getFuncaoFuncionario(), getNomeFuncionario());

        DatabaseReference referenciaFirebase = ConfiguracaoFirebase.getFirebaseFuncionario();

        String id = referenciaFirebase.push().getKey();
        func.setIdFuncionario(id);

        referenciaFirebase.child(func.getIdFuncionario()).setValue(func);
    }
    else {}
}

Producao class

public class Producao {

private String idProducao;
private String numProducao;
private String tipoProducao;
private String metaProducao;
private String tempoProducao;
private String horaDataProducao;
private String totalProducao;


public Producao(String idProducao, String numProducao, String horaDataProducao, String metaProducao, String tempoProducao, String tipoProducao, String totalProducao) {
    this.idProducao = idProducao;
    this.numProducao = numProducao;
    this.horaDataProducao = horaDataProducao;
    this.metaProducao = metaProducao;
    this.tempoProducao = tempoProducao;
    this.tipoProducao = tipoProducao;
    this.totalProducao = totalProducao;
}

public Producao() {

}

public Producao(String idProducao, String numProducao, String horaDataProducao, String metaProducao, String tempoProducao, String totalProducao) {
}

public String getIdProducao() {
    return idProducao;
}

public void setIdProducao(String idProducao) {
    this.idProducao = idProducao;
}

public String getNumProducao() {
    return numProducao;
}

public void setNumProducao(String numProducao) {
    this.numProducao = numProducao;
}

public String getTipoProducao() {
    return tipoProducao;
}

public void setTipoProducao(String tipoProducao) {
    this.tipoProducao = tipoProducao;
}

public String getMetaProducao() {
    return metaProducao;
}

public void setMetaProducao(String metaProducao) {
    this.metaProducao = metaProducao;
}

public String getTempoProducao() {
    return tempoProducao;
}

public void setTempoProducao(String tempoProducao) {
    this.tempoProducao = tempoProducao;
}

public String getHoraDataProducao() {
    return horaDataProducao;
}

public void setHoraDataProducao(String horaDataProducao) {
    this.horaDataProducao = horaDataProducao;
}

public String getTotalProducao() {
    return totalProducao;
}

public void setTotalProducao(String totalProducao) {
    this.totalProducao = totalProducao;
}

public void salvar() {
    Producao producao = new Producao(getIdProducao(), getNumProducao(), getHoraDataProducao(), getMetaProducao(), getTempoProducao(), getTipoProducao(), getTotalProducao());

    DatabaseReference refFirebase = ConfiguracaoFirebase.getFirebaseProducao();
    String id = refFirebase.push().getKey();

    producao.setIdProducao(id);
    setIdProducao(producao.getIdProducao());
    refFirebase.child(producao.getIdProducao()).setValue(producao);


}

}

Myadapter class

public class Myadapter extends Recyclerview.Adapter {

private Context context;
private List<Funcionario> f;
private List<Producao> p;

public MyAdapter(Context context, List<Funcionario> f) {
    this.context = context;
    this.f = f;

    notifyDataSetChanged();
}

public MyAdapter(Context context) {
    this.context = context;
}

public MyAdapter setFuncList(List<Producao> producaos) {
    this.p = producaos;
    notifyDataSetChanged();
    return null;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(context).inflate(R.layout.recycler_view_list_item, parent, false);

    return new ViewHolder(v);

}

@Override
public void onBindViewHolder(ViewHolder holder, @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 am using Fragment so the stretch where I look for the employee in the class Fragment

@Override public void onStart() { super.onStart(); databaseFunctioning.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’t list in recyclerview the employee and production by your id.

  • But it makes a mistake?

  • error not only when entering the object of production

1 answer

0

You have to wear one addValueEventListener for each node that will access, in this case, one for the employee (what is done) and another for the production.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.