Dialog中获取自定义控件
来源:互联网 发布:ug数控车编程软件 编辑:程序博客网 时间:2024/05/17 08:04
转载自:http://892848153.iteye.com/blog/1279249
最近写了一个自定义布局的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);
那位提供解决方法的网友说:想要获取自定义布局中的控件必须调用你所定义的View的findViewById方法,而不能像获得其他控件一样直接调用findViewById方法。。。。
最后附上dialog的自定义布局代码:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/send_email_dialog_ll"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView
- android:layout_width="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_height="wrap_content"
- android:text="To : wuxianglong098@163.com"
- android:layout_gravity="center"
- android:layout_marginTop="4dp" />
- <EditText
- android:id="@+id/send_email_dialog_et"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:inputType="textMultiLine"
- android:lines="4"
- android:hint="@string/send_email_hint"
- android:scrollbarAlwaysDrawVerticalTrack="true"
- android:layout_marginTop="9dp">
- <requestFocus></requestFocus>
- </EditText>
- </LinearLayout>
0 0
- Dialog中获取自定义控件
- Android获取dialog自定义布局中的控件
- Android获取dialog自定义布局中的控件
- Android获取Dialog自定义布局中的控件
- Android获取dialog自定义布局中的控件
- Android获取dialog自定义布局中的控件(从控件中获得参数)
- Android自定义Dialog弹窗获取Dialog中的控件ID
- 自定义dialog中组件的获取
- 自定义控件之Dialog
- 自定义dialog控件
- Android自定义控件-dialog
- 【android控件】dialog自定义布局
- 自定义dialog对话框中的控件
- 自定义控件实践之Dialog
- 自定义控件(Dialog篇)
- 提示控件之自定义Dialog
- 微信小程序自定义控件--dialog
- android 中自定义dialog
- C++去除文件名中的空格
- Empty Class(空类)的作用
- ls -l 显示文件及详细信息
- K3/ERP、fineprint8.0版cology8.1最新出炉JAVA功能越来越Fineport8.0
- UVa 230 Borrowers
- Dialog中获取自定义控件
- Swift5
- 简单rpm安装升级卸载查询以及校验操作
- Centos 7 Oracle 12C 超详细安装
- Pull解析
- C++11系列-什么是C++11
- tap事件不响应问题
- 别轻易说,我热爱编程,热爱学习
- x265不同preset下的参数集合