
我有一段代码,其中一个函数打开了一个d出窗口,以后根据该窗口内发生的事情返回一个整数.但是,当我运行它时,它直接返回整数,而无需打开任何d出窗口.
我如何告诉该函数等待返回,直到用户执行了某个 *** 作?
这是您需要时的代码:
public int initPopup(String monstername, String monsterHP){ final int monsterHPInt = Integer.parseInt(monsterHP); PopupWindow popup; TextVIEw popupText; button closePopupbutton; final Seekbar monsterHPChanger; linearLayout popupLayout; popupText = new TextVIEw(this); popupText.setText(monstername); monsterHPChanger = new Seekbar(this); monsterHPChanger.setMax(monsterHPInt); /** Will only use if necessary * monsterHPChanger.setProgress(monsterHPChanger.getMax()); */ popupLayout = new linearLayout(this); popupLayout.setorIEntation(linearLayout.VERTICAL); popupLayout.addVIEw(popupText); popupLayout.addVIEw(monsterHPChanger); //Todo: Create the layout of the popup and the popup itself popup = new PopupWindow(popupLayout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popup.setContentVIEw(popupLayout); //Creating encapsulation class to edit the monsterHP with the value of the Seekbar final MonsterHP monsterHPObject = new MonsterHP(monsterHPInt, monsterHPChanger.getProgress()); closePopupbutton = new button(this); closePopupbutton.setID(R.ID.closePopup); closePopupbutton.setText("Ok"); closePopupbutton.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { monsterHPObject.update(monsterHPChanger.getProgress()); } }); Log.println(1, "Method", "Returns " + monsterHPObject.getHP()); // Todo: reactivate when deBUG is done return monsterHPObject.getHP(); //Returning 0 for deBUG reasons return 0;}解决方法:
我正在查看您的代码,但在任何地方都看不到调用“ popup.show()”.另外,如果要等待一段时间执行 *** 作,则可以使用以下代码.
new Handler().postDelayed(new Runnable() { @OverrIDe public voID run() { // your operations (open popup?) }}, **your_delay_time**);希望对您有帮助!!
总结以上是内存溢出为你收集整理的java-如何延迟函数的return语句?全部内容,希望文章能够帮你解决java-如何延迟函数的return语句?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)