久久久久久久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>
                          主站蜘蛛池模板: 国内自拍偷拍视频 | 国产在线精品一区二区三区 | 久久精品国产一区二区电影 | 国产高清视频在线观看播放 | 一区二区精品 | 亚洲天堂影院 | 在线观看成人免费视频 | 欧美性另类 | 亚洲国产精品一区二区久久 | 六月色婷| 男女污污动态图 | 黑人巨大精品 | 狠狠亚洲| 免费精品视频一区 | 亚洲精品一区二区 | 久久综合一区二区 | 久草新在线 | 欧美精品一区在线发布 | 久久午夜视频 | 在线欧美一区 | 一级毛片免费看 | 精品欧美乱码久久久久久1区2区 | 91日日 | 久久69精品久久久久久久电影好 | 中文字幕一区二区三区四区 | 色噜噜色综合 | 中文字幕日韩欧美 | 99热这里有精品 | 91高清在线观看 | 亚洲免费一区二区 | 国产一区二区免费电影 | 999久久精品 | 黄色国产大片 | 午夜激情国产 | 一区二区三区在线免费 | 中文字幕久久精品 | 欧美精品一区在线发布 | 一区二区三区在线免费观看视频 | 天堂影院av | 免费成人高清在线视频 | 久久国产免费看 |