最近寫了一個自定義佈局的Dialog,運行效果如下:
然後我想獲取到自定義佈局中的EditText控件,並得到其中的字符串,但是使用send_email = (EditText) findViewById(R.id.send_email_dialog_et);並不能獲取到控件對象,經測試發現send_email對象爲null。。。。
沒辦法,只好到一個技術羣裏問一下別人,很幸運我找到了解決方法,關鍵代碼如下:
final View layout = inflater.inflate(R.layout.send_email_dialog,
(ViewGroup) findViewById(R.id.send_email_dialog_ll));
final EditText sendEmailCon_ET = (EditText) layout.findViewById(R.id.send_email_dialog_et);
只有主程序的組件可以通過findviewbyid得到,其他的layout需要用上述方法。