Я успешно добавил свой customView программно в свой LinearLayout. Теперь я хочу установить флажок по положению. Это мой код:Android Studio не может включить программный пакет chackbox
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/recycler_view_item_height"
android:orientation="horizontal">
<TextView
android:id="@+id/polygon_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center|left"
android:layout_marginLeft="2dp"
android:maxLines="1"
android:singleLine="true"
android:textColor="#4d4d4d"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="@+id/vin_code"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center|left"
android:layout_marginLeft="2dp"
android:maxLines="1"
android:singleLine="true"
android:textColor="#4d4d4d"
android:textSize="16dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:layout_marginLeft="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox"
android:layout_marginRight="10dp"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
</LinearLayout>
Java код:
final int childcount = linearLayout.getChildCount();
for (int i = 0; i < childcount; i++) {
View view = linearLayout.getChildAt(i);
if (i == selectedPosition) {
LinearLayout mmLinearLayout = (LinearLayout) view;
for (int j = 0; j < mmLinearLayout.getChildCount(); j++) {
View mview = mmLinearLayout.getChildAt(i);
if (mview instanceof CheckBox)
((CheckBox) mview).setChecked(true);
}
view.setBackgroundColor(activeColor);
}
}
Я debuged мой код и мой InstanceOf работает, но я не могу проверить флажок программно. Как я могу решить эту проблему? Спасибо всем
Ваш флажок не является дочерним элементом вашей линейной очереди. дайте ему идентификатор и вместо этого используйте findViewById. – njzk2