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);
}
}
}