When I select an option It opens an activity but when i finish with that activity and I returnt ot the spinner activity, the spinner is still open.
How can I dismiss it right after I select an item?
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
boolean firstPop =true;
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
if (!firstPop) {
doMyLogic();
sp.????
}
firstPop = false;
}
edit full code
public void showDropDownDialogue() {
String[] s = getResources().getStringArray(R.array.cities);
final ArrayAdapter<String> adp = new ArrayAdapter<String>(
MainActivity.this, android.R.layout.simple_spinner_item, s);
final Spinner sp = new Spinner(MainActivity.this);
sp.setPadding(5, 5, 5, 5);
sp.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
sp.setAdapter(adp);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
boolean firstPop =true;
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
if (!firstPop) {
editor.putInt("city_id", pos);
editor.commit();
Intent stationsIntent = new Intent(MainActivity.this,
StationsActivity.class);
startActivity(stationsIntent);
}
firstPop = false;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(sp);
builder.create().show();
}
Its the dialog that needs to be closed and not the spinner. SO declare AlertDialog as a field
and change dialog show like below.
And in onItemSelected add