У меня очень неловкая ситуация.Я создал пользовательский компонент макета, состоящий из 5 ImageViews:
select_players_item.xml
<?xml version="1.0" encoding="utf-8"?>
<org.lzwierko.SelectPlayerItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/armyImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/army_symbol" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_weight=".06" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".40" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".4"
android:src="@drawable/icon0"
android:visibility="invisible" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".2" >
</LinearLayout>
<ImageView
android:id="@+id/iconUser"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".4"
android:src="@drawable/icon1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_weight=".08" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".4" >
<ImageView
android:id="@+id/iconInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".4"
android:src="@drawable/icon3" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".2" >
</LinearLayout>
<ImageView
android:id="@+id/iconProfileAi"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".4"
android:src="@drawable/icon_4" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_weight=".06" />
</TableLayout>
</org.lzwierko.SelectPlayerItem>
org.lzwierko.SelectPlayerItem Класс расширяет FrameLayout:
public class SelectPlayerItem extends FrameLayout {
Теперь я включаю 4 из этих компонентов в мой другой компонент:
<include
android:id="@+id/player1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_weight="1"
layout="@layout/select_players_item" />
теперь, как вы можете видеть, я идентифицирую это с помощью
android:id="@+id/player1"
Удивительно, что во время выполнения, хотя я вижукомпоненты правильно на устройстве,
findViewById(R.id.player1)
возвращает ноль.Поэтому я проверил с помощью Hierarchy Viewer и вижу, что у этих компонентов есть идентификаторы NO_ID в идентификаторах вместо тех, которые я установил в xml-файле.
Может кто-нибудь помочь мне с этим?Мне действительно нужно получить доступ к этим компонентам по id.