1
I’m a beginner in android studio and I stuck in a part, I already looked here in the stack I saw some possible solutions but they didn’t work for me, I don’t know if it’s because of my code, come on, I have 2 spinners that receive data from firebase to complement a form, I am unable to save this form with the selected data in the spinner. If anyone can help me, I’d be most grateful. (Obs.: if someone can teach me how to better organize the code, also thank you.
public class CadastroServicos extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
EditText numeroPedido;
Spinner nomeParceiroServico;
Spinner tipoServicoServico;
EditText cliente;
EditText produto;
EditText quantidade;
EditText precoPago;
EditText dataEnvio;
ArrayList<String> item;
DatabaseReference dbReferenceParceiro;
DatabaseReference dbReferenceServico;
ValueEventListener listenerParceiro;
ValueEventListener listenerServico;
ArrayAdapter<String> adapterParceiro;
ArrayAdapter<String> adapterServico;
ArrayList<String> spinnerListParceiro;
ArrayList<String> spinnerListServico;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadastro_servicos);
numeroPedido = findViewById(R.id.editNumeroPedido);
nomeParceiroServico = findViewById(R.id.spinnerParceiro);
tipoServicoServico = findViewById(R.id.spinnerTipoServico);
cliente = findViewById(R.id.editCliente);
produto = findViewById(R.id.editProduto);
quantidade = findViewById(R.id.editQuantidade);
precoPago = findViewById(R.id.editPrecoPago);
dataEnvio = findViewById(R.id.editDataEnvio);
dbReferenceParceiro = FirebaseDatabase.getInstance().getReference("Parceiro");
spinnerListParceiro = new ArrayList<>();
adapterParceiro = new ArrayAdapter<String>(CadastroServicos.this, android.R.layout.simple_spinner_dropdown_item, spinnerListParceiro);
dbReferenceServico = FirebaseDatabase.getInstance().getReference("TipoServico");
spinnerListServico = new ArrayList<>();
adapterServico = new ArrayAdapter<String>(CadastroServicos.this, android.R.layout.simple_spinner_dropdown_item, spinnerListServico);
ArrayAdapter adapter = new ArrayAdapter<String>(CadastroServicos.this, android.R.layout.simple_spinner_dropdown_item, spinnerListParceiro);
nomeParceiroServico.setAdapter(adapterParceiro);
tipoServicoServico.setAdapter(adapterServico);
retrieveData();
inicializaFirebase();
inicializaFirebase2();
}