I have a layout like this:
<RelativeLayout
android:id="@+id/testLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="64dp"
>
<ImageButton
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"/>
<ImageButton
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="100dp"
android:visibility="invisible"/>
</RelativeLayout>
Now I want to acces the second button in java code, so this is the code section that cause NullPointerException:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.testLayout);
ImageButton b = (ImageButton) rl.getChildAt(1);
0 comments:
Post a Comment