不是这样的,,你获取的Id 跟你当前setViewConten();是无关的,我刚刚接触android ,,刚刚遇到过这样的问题。。
解决方案 »
- 如何判断点击的是ListView的哪一列
- 关于Android的存储介质
- 模拟器无法上网的问题
- Android中 从GridView向EditText中插入图片
- 怎么停止logcat继续往文件里记录?
- 问题很深奥,以致不知道如何起这个标题。求大牛们来看看。
- android 开发过程报错caused java.lang.nullpointed
- 关于eclipse的android logcat不打印的问题
- android服务端实现方案
- Android启动画面后台加载webview的问题!!!
- 继承自ImageView的组件如何在布局文件中使用
- 【进者有分】Android编译生成的ramdisk.img由谁加载到内存
我的.java文件对应的是setContentView(R.layout.main);我的另一个xml文件是my.xml,里面有
<Button android:text="ggyy" android:id="@+id/btb" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>R文件里面也有id 为 public static final int btb=0x7f060009;了但我在.java文件里面
Button btb = (Button)findViewById(R.id.btb);得到btb总是为null奇了怪了
inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.my, null);
Button btb = (Button)view.findViewById(R.id.btb);ps:本人初学,说的不对还请见谅。
4楼方法得到btb不为null了我的代码中
有 LinearLayout root = (LinearLayout)findViewById(R.id.root);
想把btb放入到root中,代码为
root.addView(btb);程序运行老是出错误。这个怎么解决呢???其他xml得到的控件不能addView到root中????
root.addView(btb);
这一句就会在运行中出错。
不在内存中的话,为什么LayoutInflater得到的btb不为空呢????
为什么这么纠结呢,原因前面提到了 xml文件时图形化的布局,总是方便点。
这个view到是可以。。为什么addview view 里面的btb就不行呢???是我什么地方可能弄错了??
以后整个小局部的布局用xml做好,然后添加入,也能够符合你的预期
03-15 07:07:29.652: ERROR/AndroidRuntime(1112): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.