android - Spinner onItemSelected does not work -
private spinner spinnermonth; public view oncreateview(layoutinflater inflater , @nullable viewgroup container , @nullable bundle savedinstancestate) { super.oncreateview(inflater, container, savedinstancestate); _view = inflater.inflate(r.layout.fragment_spinnermonth, container, false); // month spinnermonth = (spinner) _view.findviewbyid(r.id.spinnermonth); spinnermonth.setadapter(monthadapter); spinnermonth.setselection(_selectedmonth - 1); return _view; } private void savedata() { spinnermonth.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> adapterview, view view, int i, long l) { log.d("month",i); } @override public void onnothingselected(adapterview<?> adapterview) { } }); }
my codes above. if determine global spinner, onitemselected not work. if determine local spinner, work. why happen? need global spinner.
find solution
public view oncreateview(layoutinflater inflater , @nullable viewgroup container , @nullable bundle savedinstancestate) { super.oncreateview(inflater, container, savedinstancestate); _view = inflater.inflate(r.layout.fragment_spinnermonth, container, false); // month spinnermonth = (spinner) _view.findviewbyid(r.id.spinnermonth); spinnermonth.setadapter(monthadapter); spinnermonth.setselection(_selectedmonth - 1); spinnermonth.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> adapterview, view view, int i, long l) { log.d("month",i); } @override public void onnothingselected(adapterview<?> adapterview) { } }); return _view; }
Comments
Post a Comment