[英]Findviewbyid always returns null
我正在以编程方式将视图添加到线性布局(工作正常)。 但是,当我尝试获取1个特定的图像视图ivBsquadBroken时,该图像视图始终返回null。 所有其他视图正确返回。 我已将其简化为仅两个imageview,而我尝试过的任何操作都不会返回该视图。 另一个imageview正确返回,我可以设置图像,设置可见性等。
另外,不确定为什么,但是如果我将R.layout.rowbridge_squads声明为正确的相对布局而不是线性布局,则会中断。
谢谢您的帮助!
用于以编程方式将相对布局添加到线性布局的代码。
ArrayList<Squadron> tmpships = ((ExtendedApp) getActivity().getApplication()).getCurrentSquad();
LinearLayout tmpLL = (LinearLayout) mainView.findViewById(R.id.llBSquadList);
tmpLL.removeAllViews();
for(int i = 0; i <= tmpships.size() - 1; i++){
LinearLayout shiplayout = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.rowbridge_squads, tmpLL, false);
ImageView tmpIB = (ImageView) shiplayout.findViewById(R.id.ivBsquadicon);
***!! always returns null - - >*** ImageView blasted = (ImageView) shiplayout.findViewById(R.id.ivBsquadBroken);
Squadron tmpsquad = tmpships.get(i);
布局膨胀
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/llBrowsquaditem"
android:background="@color/bridge_cream">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ivBsquadicon"
android:src="@android:drawable/ic_delete"
android:adjustViewBounds="true"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ivBsquadBroken"
android:src="@android:drawable/ic_delete"
android:adjustViewBounds="true"/>
</RelativeLayout>
没关系。 我有多个尚未更新的横向和纵向配置。
用户错误...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.