So i'm starting a application and the first thing to do is make a description of a city when the city is selected. I can show the description but it make the description of all the cities on the same time and it don't come out when i select another city : it add more and more .
this is my code :
public class Main extends Activity implements OnItemClickListener, OnItemSelectedListener {
TextView description;
Spinner spin;
ArrayAdapter adapter_city;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
description = (TextView)findViewById(R.id.description);
spin = (Spinner)findViewById(R.id.spin);
adapter_city = ArrayAdapter.createFromResource(this, R.array.Cities, android.R.layout.simple_spinner_item);
adapter_city.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter_city);
spin.setOnItemSelectedListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
}
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
switch(position){
case 0 : description.append(getString(R.string.Paris));
case 1 : description.append(getString(R.string.Chicago));
case 2 : description.append(getString(R.string.NewYork));
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
thank you .