How to identify the selected item in SPINNER and insert it into the SQLITE database.
I can do the insert in Sqlite using the data provided in EditText, but I am not able to create a way to do something similar with SPINNER.
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recadastramento);
marca = (EditText) findViewById(R.id.ed_marca);
modelo = (EditText) findViewById(R.id.ed_modelo);
constante = (EditText) findViewById(R.id.ed_constante);
data_fabricacao = (EditText) findViewById(R.id.ed_fabricacao);
salvar = (Button) findViewById(R.id.btn_salvar);
myDb = new DatabaseHelper(this);
AddData();
spiner_constante = (Spinner) findViewById(R.id.sp_constante);
spiner_constante.setOnItemSelectedListener(this);
loadSpinnerData();
private void loadSpinnerData() {
DatabaseHelper db = new DatabaseHelper(getApplicationContext());
List<Integer> constante = db.GetAllConstante();
ArrayAdapter<Integer> dataAdapter3 = new ArrayAdapter<Integer> (this,android.R.layout.simple_spinner_item,constante);
spiner_constante.setAdapter(dataAdapter3);
dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
public void AddData() { // AQUI É FEITO O INSERT DOS DADOS DOS EDITTEXT, NO SQLITE
salvar.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isInserted = myDb.insertData(marca.getText().toString(), modelo.getText().toString(), constante.getText().toString(), data_fabricacao.getText().toString());
}
}