1
I have a question in my code, I’m trying to take the value of Spinner and record it in the bank, but I can’t make the spinner have String value. In case he’s giving me error at the time of setText, at the end of the code. " Cannot resolve method 'setText(java.lang.String)'"
public class editarContato extends Activity {
Spinner spinner; String[] arraySpinner;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editar_contato);
spinner = (Spinner) findViewById(R.id.spinner);
this.arraySpinner = new String[] {"SP", "RJ", "SC"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_spinner_item, arraySpinner);
spinner.setAdapter(adapter);
btAtualizar = (Button) findViewById(R.id.atualizar);
carregaDetalhesContato();
btAtualizar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
datasource = new DBAdapter(editarContato.this);
datasource.open();
contato = datasource.getContato(idContato);
datasource.close();
datasource.AlterarContato(spinner.getSelectedItem().toString());
datasource.close();
}
});
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView parent,View view, int pos, long id) {
Object item = parent.getItemAtPosition(pos);
}
public void onNothingSelected(AdapterView parent){}
});
}
public void carregaDetalhesContato() {
idContato = getIntent().getIntExtra("id", 0);
datasource = new DBAdapter(this);
datasource.open();
contato = datasource.getContato(idContato);
datasource.close();
spinner.setText(contato.getSpinner());
}
}