android - how to disable setOnItemSelectedListener(listener) Toast message -
i have listener show toast message when user clicks on spinner , selects item.
but when set value of spinner programatically want disable toast message. how do it.
i have tried setonitemselectedlistener(null) before programmatically setting value of spinner setonitemselectedlistener(listener) after toast message still shows no matter do.
thanks in advance.
this done inside oncreate btw. want disable toast messaging when oncreate sets default values spinner.
here's listener
private onitemselectedlistener listener = new onitemselectedlistener() { public void onitemselected(adapterview<?> parent, view view, int position, long id) { string item = (string) parent.getitematposition(position); toast = toast.maketext(getbasecontext(), weather.temp_description.get(item), toast.length_short); if (mtemp.getonitemselectedlistener() != null) { toast.show(); } }; public void onnothingselected(adapterview<?> parent) { } };
and here's have in oncreate()
bundle extras = getintent().getextras(); if (extras != null) { mtemp.setonitemselectedlistener(null); string weather = extras.getstring("weather"); string tempstr = extras.getstring("temp_str"); if (weather.equals(weather.unavailable)) { mweather.setselection(adapter.getposition(weather.any_weather)); if (toast != null) { toast.cancel(); toast.getview().setvisibility(view.invisible); toast = null; } } else { mweather.setselection(adapter.getposition(weather)); mtemp.setselection(tempadapter.getposition(tempstr)); if (toast != null) { toast.cancel(); toast.getview().setvisibility(view.invisible); toast = null; } } } mtemp.setonitemselectedlistener(listener);
i tried many different things that's why see weird if checks, tried setting boolean variable in class , didn't work either.
global boolean:
public boolean userset = true;
on create:
bundle extras = getintent().getextras(); if (extras != null) { userset = false; mtemp.setonitemselectedlistener(null); string weather = extras.getstring("weather"); string tempstr = extras.getstring("temp_str"); if (weather.equals(weather.unavailable)) { mweather.setselection(adapter.getposition(weather.any_weather)); if (toast != null) { toast.cancel(); toast.getview().setvisibility(view.invisible); toast = null; } } else { mweather.setselection(adapter.getposition(weather)); mtemp.setselection(tempadapter.getposition(tempstr)); if (toast != null) { toast.cancel(); toast.getview().setvisibility(view.invisible); toast = null; } } mtemp.setonitemselectedlistener(listener); }
listener:
private onitemselectedlistener listener = new onitemselectedlistener() { public void onitemselected(adapterview<?> parent, view view, int position, long id) { if (!userset) { userset = true; return; } }
Comments
Post a Comment