I want to show the data in the txtloc, but it always shows the first data of the spinner and does not change when I select another spinner data. On the other hand, the txtpro does change when I select another data inside its spinner ... How could I make both spinners save their data in a TextView and change each time I select another data within their spinner?
This is my code
txtpro = (TextView) findViewById(R.id.txtpro);
txtloc = (TextView) findViewById(R.id.txtloc);
spinnerPro = (Spinner) findViewById(R.id.spinnerProvincia);
spinnerLoc = (Spinner) findViewById(R.id.spinnerLocalizacion);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,
R.array.array_provincias,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerPro.setAdapter(adapter);
spinnerPro.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
int[] localidades = {R.array.array_sevilla, R.array.array_malaga};
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,
localidades[i],
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerLoc.setAdapter(adapter);
txtloc.setText(spinnerLoc.getSelectedItem().toString());
txtpro.setText(adapterView.getItemAtPosition(i).toString());
}
And these array I have in my String.xml file
<string-array name="array_provincias">
<item>Sevilla</item>
<item>Malaga</item>
</string-array>
<string-array name="array_sevilla">
<item>Tomares</item>
<item>Camas</item>
</string-array>
<string-array name="array_malaga">
<item>Casares</item>
<item>Estepona</item>
</string-array>