久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <i id='qwFRl'><tr id='qwFRl'><dt id='qwFRl'><q id='qwFRl'><span id='qwFRl'><b id='qwFRl'><form id='qwFRl'><ins id='qwFRl'></ins><ul id='qwFRl'></ul><sub id='qwFRl'></sub></form><legend id='qwFRl'></legend><bdo id='qwFRl'><pre id='qwFRl'><center id='qwFRl'></center></pre></bdo></b><th id='qwFRl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qwFRl'><tfoot id='qwFRl'></tfoot><dl id='qwFRl'><fieldset id='qwFRl'></fieldset></dl></div>

    1. <tfoot id='qwFRl'></tfoot>
    2. <legend id='qwFRl'><style id='qwFRl'><dir id='qwFRl'><q id='qwFRl'></q></dir></style></legend>
        <bdo id='qwFRl'></bdo><ul id='qwFRl'></ul>
    3. <small id='qwFRl'></small><noframes id='qwFRl'>

    4. 如何在不同類的非 UI 線程中創(chuàng)建對話框?

      How to create a dialog box in a non-UI thread in a different class?(如何在不同類的非 UI 線程中創(chuàng)建對話框?)

        1. <small id='65cBW'></small><noframes id='65cBW'>

          <legend id='65cBW'><style id='65cBW'><dir id='65cBW'><q id='65cBW'></q></dir></style></legend>
            <bdo id='65cBW'></bdo><ul id='65cBW'></ul>

                <i id='65cBW'><tr id='65cBW'><dt id='65cBW'><q id='65cBW'><span id='65cBW'><b id='65cBW'><form id='65cBW'><ins id='65cBW'></ins><ul id='65cBW'></ul><sub id='65cBW'></sub></form><legend id='65cBW'></legend><bdo id='65cBW'><pre id='65cBW'><center id='65cBW'></center></pre></bdo></b><th id='65cBW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='65cBW'><tfoot id='65cBW'></tfoot><dl id='65cBW'><fieldset id='65cBW'></fieldset></dl></div>
                <tfoot id='65cBW'></tfoot>
                  <tbody id='65cBW'></tbody>
                本文介紹了如何在不同類的非 UI 線程中創(chuàng)建對話框?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在 android 中開發(fā)一個非常簡單的游戲(在非 UI 線程中運行),我想這樣做,當(dāng)游戲結(jié)束時,它會顯示一個帶有分?jǐn)?shù)的自定義對話框,但類是不在 MainActivity 類中.我不知道如何在沒有任何錯誤的情況下在線程中創(chuàng)建對話框.

                I'm developing a very simple game in android(that runs in a non-UI thread), I want to make that, when the game is over, it shows a custom dialog box with the score, but the class isn't in the MainActivity class. I can't figure out how to create the dialog in the thread whitout getting any error.

                推薦答案

                有很多方法可以做到這一點.一種方法是將您的 context 傳遞給游戲的類構(gòu)造函數(shù),以便能夠通過它訪問 UI.

                There are so many ways to do that. One way is to pass your context to the class constructor of the game to be able to access the UI through it.

                public class MyGame {
                   private Context context;
                   private Handler handler;
                
                   public MyClass(Context context) {
                      this.context = context;
                      handler = new Handler(Looper.getMainLooper());
                   }
                   ...
                }
                

                以及從活動初始化時

                MyGame game = new MyGame(this);
                

                要在您的游戲類中顯示對話框,只需使用此代碼

                and to show the dialog in your game class, just use this code

                handler.post(new Runnable() {
                   public void run() {
                      // Instanitiate your dialog here
                      showMyDialog();
                   }
                });
                

                以及如何顯示一個簡單的 AlertDialog.

                and this how to show a simple AlertDialog.

                private void showMyDialog() {
                  new AlertDialog.Builder(context)
                    .setTitle("Som title")
                    .setMessage("Are you sure?")
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) { 
                            // continue with delete
                        }
                     })
                    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) { 
                            // do nothing
                        }
                     })
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .show();
                }
                

                這篇關(guān)于如何在不同類的非 UI 線程中創(chuàng)建對話框?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                Get current location during app launch(在應(yīng)用啟動期間獲取當(dāng)前位置)
                locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)
                    <bdo id='sBemb'></bdo><ul id='sBemb'></ul>

                  • <legend id='sBemb'><style id='sBemb'><dir id='sBemb'><q id='sBemb'></q></dir></style></legend>

                      <small id='sBemb'></small><noframes id='sBemb'>

                      • <i id='sBemb'><tr id='sBemb'><dt id='sBemb'><q id='sBemb'><span id='sBemb'><b id='sBemb'><form id='sBemb'><ins id='sBemb'></ins><ul id='sBemb'></ul><sub id='sBemb'></sub></form><legend id='sBemb'></legend><bdo id='sBemb'><pre id='sBemb'><center id='sBemb'></center></pre></bdo></b><th id='sBemb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sBemb'><tfoot id='sBemb'></tfoot><dl id='sBemb'><fieldset id='sBemb'></fieldset></dl></div>
                        <tfoot id='sBemb'></tfoot>
                            <tbody id='sBemb'></tbody>
                          主站蜘蛛池模板: 欧美成ee人免费视频 | 免费观看一级毛片 | 精品久 | 精品视频一区二区三区在线观看 | 大久| 五月综合激情在线 | 精品国产视频 | 操人网站 | 免费视频中文字幕 | 欧美一级全黄 | 香蕉av免费| 国产www. | 精品一区免费 | 免费毛片网 | 亚洲成人网在线播放 | 91色视频在线观看 | 日韩精品久久一区二区三区 | 日本在线视频不卡 | 高清视频一区二区三区 | 欧美一级视频免费看 | 九九亚洲| 日韩亚洲一区二区 | 久久成人一区 | 天天澡天天狠天天天做 | 国产一区二区三区视频 | 欧美电影免费观看 | 日韩福利电影 | 91精品国产综合久久精品 | 观看av| 天天看天天爽 | 久久久久国产精品一区三寸 | 日本亚洲欧美 | www.亚洲一区二区 | 麻豆精品久久 | 亚洲精品9999 | 日韩亚洲欧美综合 | 毛片免费看的 | 美女久久 | 中文字幕成人在线 | 91一区二区 | 久久99精品久久久久 |