Pass the data of a spinner to mysql

0

Hello, so my question is small and simple (but I can not solve kkk) I just want to know how to pass the value that was selected in Spinner to the database when clicking a button, here my script

   sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int posicao, long id) {
            nome = parent.getItemAtPosition(posicao).toString();
        }
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    btadcionar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                String aluno = adicionarnome.getText().toString();
                String patrulha = nome;

            if (aluno.isEmpty()) {
                Toast.makeText(getActivity(), "Nenhum campo pode esta vaio", Toast.LENGTH_SHORT).show();
            } else {

                url = "http://smestudios.000webhostapp.com/adadmirin/registre.php";

                parametros = "aluno=" + aluno + "patrulha=" + patrulha;

                new SolicitaDados().execute(url);
            }
        }
    });
}
@SuppressLint("StaticFieldLeak")
private class SolicitaDados extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        return Conexao.postDados(urls[0], parametros);
    }

    @Override
    protected void onPostExecute(String resultado) {
        Toast.makeText(getActivity(), "Nenhum campo pode esta vazio", Toast.LENGTH_SHORT).show();
        adicionarnome.setText(resultado);
    }
}

}

    
asked by anonymous 18.07.2018 / 21:41

1 answer

0

I think it's better to take the object and then cast it.

Object objeto = parent.getItemAtPosition(posicao);

String nome = ((String) objeto).getNome();

Here you already have the name, now just use your class new SolicitaDados() and commit in the database, I do not know The content of SoliciDados ().

Edit your question and show the content of this class so we can help you.

    
19.07.2018 / 20:49