-1
How to pass to a variable the value selected in a spineer at the moment the user selects some of the options?
I tried to implement this option, but I was unsuccessful.
Follow my code in case anyone can tell me where the bug is:
public class desafio extends AppCompatActivity {
EditText campo1, campo2;
int pos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_desafio);
String[] operacoes = {"+", "-", "*", "/"};
Spinner spin = (Spinner) findViewById(R.id.spinner_operacoes);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, operacoes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
pos = spin.getSelectedItemPosition();
//teste
Toast.makeText(getApplicationContext(), + pos, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}