android - Load Spinner content -


before marking duplicate please read post.

i using spinner in app , populate data server in oncreate method.
works fine if during oncreate user having internet connection.
in other case spinner having 1 item "select item"
need solution load again spinner's data @ run time
(if hasn't been loaded during oncreate()) each time user clicks spinner.
ideal solution onfocuschanelistenner - here upload data server when user clicks on spinner.
unfortunately seemes not work , can not see choice.

spinner spinner = (spinner) rootview.findviewbyid(r.id.spinner); spinner.setonfocuschangelistener(new view.onfocuschangelistener() {             @override             public void onfocuschange(view v, boolean hasfocus) {                 // here would great update when receive focus             }         }); 

i thought implementation of custom spinner, onitemselected called when spinner having 1 or 0 itebs.
here user has select (or nothing) , return again in order see updated data seemes not ideal.
should check whether data has been loaded after period of time without relying on user's interraction spinner?

if want load data on spinner interaction use ontouchlistener.

spinner spinner = (spinner) rootview.findviewbyid(r.id.spinner); spinner.setontouchlistener(new view.ontouchlistener() {     @override     public boolean ontouch(view v, motionevent event) {        if(event.getaction() == motionevent.action_up){           // load data here        }        return false;     } }); 

Comments