第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

警報(bào)對話框未從其他非活動(dòng)類顯示

警報(bào)對話框未從其他非活動(dòng)類顯示

溫溫醬 2022-09-14 17:19:10
我正在嘗試顯示來自另一個(gè)類的警報(bào)對話框。我在堆棧溢出中查找了許多問題,但沒有一個(gè)有效。我有兩個(gè)類和.我正在嘗試顯示警報(bào)對話框,其中在 中指定。MainActivity.javaCustomInputDialog.javaCustomInputDialog.javaMainActivity.java在我的我有以下代碼:MainActivity.javaArrayList<CustomInputDialog.Field> fields = new ArrayList<>(Arrays.asList(                        new CustomInputDialog.Field(CustomInputDialog.Field.TYPE.TEXT, "Name", "", null),                        new CustomInputDialog.Field(CustomInputDialog.Field.TYPE.DATE, "Start Date", "", null),                        new CustomInputDialog.Field(CustomInputDialog.Field.TYPE.DATE, "End Date", "", null)                ));                ArrayList<String> result = CustomInputDialog.showDialog(MainActivity.this, "Title", fields);在我的我有以下代碼:CustomInputDialog.javafinal class CustomInputDialog {    private static final String TAG = "CustomInputDialog";    private static final String dateUISeparator = " : ";    static ArrayList<String> showDialog(final Context context, String title, final ArrayList<Field> fields) {        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);        final LinearLayout layout = new LinearLayout(context);        layout.setOrientation(LinearLayout.VERTICAL);        final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);        layoutParams.setMargins(10, 10, 10, 10);        final ArrayList<View> uis = new ArrayList<>();        for (final Field field : fields) {            final View ui;            switch (field.type) {                 /**To long code it just creates specified views and saves it in `ui` variable*/            }            ui.setLayoutParams(layoutParams);            Log.d(TAG, "showDialog: ui added");            layout.addView(ui);            uis.add(ui);        }   在調(diào)試時(shí),事實(shí)證明沒有拋出異常,但仍然在方法中顯示變量 :不可見。alertDialogshowDialog
查看完整描述

1 回答

?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊

問題似乎來自CountDownLatch,它阻塞了線程,你應(yīng)該在你的自定義對話框類中創(chuàng)建一個(gè)接口,在那里你有一個(gè)(或者你想調(diào)用它的任何內(nèi)容)你在其他地方實(shí)現(xiàn)。onResult()


您必須將一個(gè)偵聽器傳遞給您的實(shí)現(xiàn),并在您的OK按鈕中調(diào)用showDialog()onResult()onClicklistener.onResult()


接口(在自定義輸入對話框中.java):


interface CustomInputDialogListener{

    void onResult(ArrayList<String> result);

}

要傳遞給顯示的新參數(shù):


static void showDialog(final Context context, String title, final ArrayList<Field> fields, final CustomInputDialogListener listener) {

...

}

單擊“確定”按鈕的末尾:”


dialog.dismiss();

listener.onResult(result);

//latch.countDown(); //you don't need that anymore

Log.d(TAG, "showDialog: latch count down 1");

您可以刪除閂鎖創(chuàng)建和嘗試/捕獲塊,并在末尾使用等待和返回語句


//Log.d(TAG, "showDialog: latch created");

//final CountDownLatch latch = new CountDownLatch(1);


/*try {

    Log.d(TAG, "showDialog: latch await");

    latch.await();

} catch (InterruptedException e) {

    e.printStackTrace();

} finally {

    if (result.isEmpty()) {

        return null;

    } else {

        return result;

    }

}*/

在您的主要活動(dòng)中.java您有2個(gè)選擇:


實(shí)現(xiàn)自定義輸入對話框中的接收器并將其傳遞給showDialog


您的主要活動(dòng)的標(biāo)題應(yīng)如下所示:


public class MainActivity extends AppCompatActivity implements CustomInputDialog.CustomInputDialogListener {

    ...

}

并且您必須在搜索結(jié)果() 上實(shí)現(xiàn):


@Override

public void onResult(ArrayList<String> result) {

    this.result = result;

    doThings();

}

當(dāng)你調(diào)用顯示方言()時(shí),你傳遞這個(gè):


CustomInputDialog.showDialog(Test14dialog.this, "Title", fields, this);

您直接實(shí)現(xiàn) onResult :


CustomInputDialog.showDialog(Test14dialog.this, "Title", fields, new CustomInputDialog.CustomInputDialogListener() {

        @Override

        public void onResult(ArrayList<String> result) {

            this.result = result;

            doThings();

        }

    });

顯示對話框時(shí)不應(yīng)阻止線程


查看完整回答
反對 回復(fù) 2022-09-14
  • 1 回答
  • 0 關(guān)注
  • 110 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)