Return int from dialog Android -


i have next code, i'm trying return value of "players" in method, based on user selection. problem can onclick method of dialog, idea?

    public int dialogoinicial(){     int players = 1;     final string[] playersarray = {"1","2","3","4","5","6"};     alertdialog.builder dialog = new alertdialog.builder(this);     dialog.settitle("nÂș "+getstring(r.string.players)+":");     dialog.setsinglechoiceitems(playersarray, -1, new dialoginterface.onclicklistener() {         public void onclick(dialoginterface dialog, int player) {             players = integer.parseint(playersarray[player]);         }     });     dialog.show();      return players; } 

this problem here return players executed while dialog being shown. simple solution make players variable class level variable instead of local variable function. can make function return void since won't able return anything. android dialogs asynchronous.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -