Pass data from a spinner to mysql

Asked

Viewed 69 times

0

Hello, so my doubt is small and simple (but I can not solve kkk) just want to know how to pass the value that was selected in Spinner to the database by 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);
    }
}

}

1 answer

1


I think I’d better take the object and then cast it

Object objeto = parent.getItemAtPosition(posicao);

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

Here Voce already has the name, now just use its class new SolicitaDados() and commit to the database, I don’t know The content of Request Data().

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

  • Thanks bro, c my broke a branch

Browser other questions tagged

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