AlertDialog中獲取自定義控件

最近寫了一個自定義佈局的Dialog,運行效果如下:

0_1311671879yxXs.gif

然後我想獲取到自定義佈局中的EditText控件,並得到其中的字符串,但是使用send_email = (EditText) findViewById(R.id.send_email_dialog_et);並不能獲取到控件對象,經測試發現send_email對象爲null。。。。

沒辦法,只好到一個技術羣裏問一下別人,很幸運我找到了解決方法,關鍵代碼如下:

  1. final View layout = inflater.inflate(R.layout.send_email_dialog,  

  2.                 (ViewGroup) findViewById(R.id.send_email_dialog_ll));  

  3. final EditText sendEmailCon_ET = (EditText) layout.findViewById(R.id.send_email_dialog_et);

只有主程序的組件可以通過findviewbyid得到,其他的layout需要用上述方法。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章