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

Android - 自定義對話框 - 無法從 EditText 獲取文本

Android - Custom Dialog - Can#39;t get text from EditText(Android - 自定義對話框 - 無法從 EditText 獲取文本)
本文介紹了Android - 自定義對話框 - 無法從 EditText 獲取文本的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我的自定義對話框有問題.
我的對話框由 TextViewEditText 和Ok"按鈕組成.單擊確定"后,它應(yīng)該從 EditText 字段中獲取文本并將其分配給 Activity 中定義的字符串變量名稱".
一切似乎都正常,沒有錯(cuò)誤等,但是文本"始終是一個(gè)空字符串.
我閱讀了一些有關(guān)此類問題的主題,但是我不確定我應(yīng)該在這里進(jìn)行哪些調(diào)整.
我對 Android 編程很陌生,所以如果有人能向我解釋這個(gè)問題,我將不勝感激.提前致謝.

I have a problem with a custom dialog.
My dialog consists of a TextView, EditText and an "Ok" Button. After clicking "Ok", it should get the text from EditText field and assign it to the String variable "name" defined in the Activity.
Everything seems to work, no errors etc, however "text" is always an empty String.
I read some topics about such problems, however I'm not really sure what adjustments I should make here.
I'm quite new to Android programming, so I'd be grateful if somebody could explain the problem to me. Thanks in advance.

     final Dialog dialog = new Dialog(MyActivity.this);
     dialog.setContentView(R.layout.custom_dialog);
     dialog.setTitle("Title");

     final View layout = View.inflate(this, R.layout.custom_dialog, null);
     Button button = (Button) dialog.findViewById(R.id.dialog_ok);
     button.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
                EditText edit=(EditText)layout.findViewById(R.id.dialog_edit);
                String text=edit.getText().toString();

                name=text;

                dialog.dismiss();
         }
     });   

     dialog.show();

推薦答案

您正在對不需要的布局進(jìn)行膨脹.如您所見,我修復(fù)了您的代碼,我刪除了您的膨脹行并更改了您嘗試查找 EditText 視圖的行.

You are inflating a layout where it is not needed. I fixed your code as you see I removed your line where it inflates and changed the line where you try to find the EditText view.

final Dialog dialog = new Dialog(MyActivity.this);
 dialog.setContentView(R.layout.custom_dialog);
 dialog.setTitle("Title");

 Button button = (Button) dialog.findViewById(R.id.dialog_ok);
 button.setOnClickListener(new OnClickListener() {
     public void onClick(View v) {

            EditText edit=(EditText)dialog.findViewById(R.id.dialog_edit);
            String text=edit.getText().toString();

            dialog.dismiss();
            name=text;

     }
 });   


dialog.show();

這篇關(guān)于Android - 自定義對話框 - 無法從 EditText 獲取文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標(biāo)簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動(dòng)?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉(zhuǎn)對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點(diǎn)擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設(shè)置為僅接受 Android 中的數(shù)值?)
主站蜘蛛池模板: 国产精品久久久久久久午夜片 | www.99热.com| 99热.com| 国产中文在线 | 久久婷婷麻豆国产91天堂 | 久久国产传媒 | 狠狠插天天干 | 日本特黄特色aaa大片免费 | 久久精品国产久精国产 | 久久人人网 | 老头搡老女人毛片视频在线看 | 在线免费黄色小视频 | 精品一区在线 | 国产精品亚洲视频 | 午夜视频在线 | 亚洲成人福利视频 | 天天干天天操天天看 | 精品一区二区三区在线视频 | 日韩成人av在线 | 天天碰夜夜操 | 在线免费观看黄色 | 精品日韩在线 | 亚洲精品一区二区在线观看 | 亚洲欧洲中文日韩 | 国产精品99久久久久久动医院 | 中文字幕在线精品 | 国产精品视频在线观看 | 亚洲精品乱码久久久久久蜜桃 | 亚洲一区二区三区四区五区午夜 | 国产区免费视频 | 特黄级国产片 | 夜夜爽99久久国产综合精品女不卡 | 国产综合久久久久久鬼色 | 一级片av | 天天久久 | 国产成人精品区一区二区不卡 | 日韩在线不卡视频 | 一区二区三区影院 | 日韩av看片| 91精品导航 | 亚洲一区在线播放 |