Android 小发现:xml里定义的组件取出始终为null
来源:互联网 发布:个人记帐软件 编辑:程序博客网 时间:2024/05/29 15:41
先看下列xml代码:
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wordBgRL"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/dictionaryButton"
android:background="@drawable/dictionary_btn_bg"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
style="@style/WrapContentWidgetStyle"
/>
</RelativeLayout>
在java代码里取出wordBgRL 始终为null;
wordBgRL = (RelativeLayout)findViewById(R.id.wordBgRL); // wordBgRL alwasys == null
dictionaryButton = (Button)findViewById(R.id.dictionaryButton); // dictionaryButton != null
后来发现你必须自己另写一个RelativeLayout,可能因为 xmlns:android="http://schemas.android.com/apk/res/android" 它存在的原因吧。
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="@+id/wordBgRL"
style="@style/FillParentWidgetStyle"
>
<Button
android:id="@+id/dictionaryButton"
android:background="@drawable/dictionary_btn_bg"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
style="@style/WrapContentWidgetStyle"
/>
</RelativeLayout>
</RelativeLayout>
- Android 小发现:xml里定义的组件取出始终为null
- 通知栏PendingIntent传递参数始终为null的问题
- xml的namespace的问题 取xmlnode或xmlnodelist返回为null发现的
- mysql如何取出为null的字段并进行更新
- mysql如何取出为null的字段并进行更新
- Android ADB始终为unautorized的解决
- Spring取出bean的方法和xml里的配置
- 判断从TextView里取出的字符串是否为空
- 数据库里有数据但是python取出来发现是空的
- MVC4实现文件上传,为什么后台的file始终为null
- Android中发现的方向键旋转定义
- c#里SQL数据库里取出来的数值判断是否为空
- C#三种判断数据库中取出的字段值是否为空(NULL) 的方法
- C#判断数据库中取出的字段值是否为空(NULL)
- 惊天发现 “回收站”里的小秘密
- php 语法里0不等于null为空的解决办法
- Android布局发现的小问题
- Java中字符串定义,初始化,赋值为null的区别
- showModalDialog关闭子窗口刷新主窗口
- vector与list区别
- 窗口坐标获取 windows
- 并发编程【正确使用 Volatile 变量】
- UIViewConllor的viewDidLoad, viewWillDisappear, viewWillAppear等区别(生命周期)
- Android 小发现:xml里定义的组件取出始终为null
- Java扫描指定目录文件
- JDK环境变量配置
- 用AJAX异步交互返回xml文件从jsp页面中读取并用表格显示
- ubuntu rfkill 启动无线网卡等无线设备
- CVS搭建
- vector 的应用VC++
- Linux设备模型(上)之底层模型
- Ubuntu10.10设置固定ip