当我选择一个选项时,它会打开一个活动,但是当我完成该活动并返回微调器活动时,微调器仍处于打开状态。
选择项目后如何立即关闭它?
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;
}
编辑完整代码
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();
}