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

如何從 AlertDialog 獲取結果?

How can I get the results from an AlertDialog?(如何從 AlertDialog 獲取結果?)
本文介紹了如何從 AlertDialog 獲取結果?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用 AlertDialog.Builder 顯示一個對話框以提示用戶輸入密碼,然后我想將該密碼保存在首選項中,但是我不知道如何從警報對話框中獲取結果輸入法.

I am using an AlertDialog.Builder to display a dialog to prompt the user to enter a password, I then want to save that password in a preference, however I can't figure out how to get the result from the alert dialog's input method.

這基本上是我想做的事情:

Here is essentially what I would like to be able to do:

    String result;
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setTitle("Please enter a password");
    final EditText input = new EditText(this);
    b.setView(input);
    b.setPositiveButton("OK", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int whichButton)
        {
           //I get a compile error here, it wants result to be final.
           result = input.getText().toString();
        }
    });
    b.setNegativeButton("CANCEL", null);
    b.create().show();

但是,我愿意做諸如 showDialog(int); 之類的事情,然后使用 onCreateDialog(int) 方法并以某種方式設置結果并以某種方式接收它其他方法,但我不知道如何進行最后一部分.

However, I am open to doing something such as showDialog(int); then using the onCreateDialog(int) method and somehow setting the result and receiving it in some other method, but I have no idea how to go about the last part.

推薦答案

public class MyActivity extends Activity {
    private String result;

    void showDialog() {
        AlertDialog.Builder b = new AlertDialog.Builder(this);
        b.setTitle("Please enter a password");
        final EditText input = new EditText(this);
        b.setView(input);
        b.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                result = input.getText().toString();
            }
        });
        b.setNegativeButton("CANCEL", null);
        b.show();
    }
}

這篇關于如何從 AlertDialog 獲取結果?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 亚洲成人三级 | 综合久久久久 | 亚洲v日韩v综合v精品v | 久久久久久成人 | 亚洲综合无码一区二区 | 亚洲精品久久久一区二区三区 | 欧美一级特黄aaa大片在线观看 | 亚洲精品一区中文字幕乱码 | 综合五月| 国产一二区视频 | 国产一区91精品张津瑜 | 精品国产18久久久久久二百 | 国产精品欧美精品日韩精品 | 久久草在线视频 | 五月婷婷丁香 | 亚洲成人自拍网 | 日韩电影中文字幕在线观看 | 欧美日韩一区二区三区四区五区 | 欧美日韩久久 | 天天宗合网 | 久久久精 | 激情 一区| 91精品国产一区二区三区 | 爱综合| 亚洲午夜精品一区二区三区他趣 | 高清黄色网址 | 中文字幕不卡在线观看 | 精品三级在线观看 | 一本一道久久a久久精品综合蜜臀 | 宅男伊人 | 久干网 | 国产精品美女 | 亚洲精品电影网在线观看 | 中文字幕11页 | 天天狠狠 | 91美女在线观看 | 国产精品久久 | 久久久免费| 91av免费版 | 人人干人人干人人干 | av黄色在线 |