ボタンをクリックするだけでカスタムビューを作成しています。カスタム ビューは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/friendImage"
android:layout_width="100dp"
android:layout_height="match_parent"
android:contentDescription="Person Image"
app:srcCompat="@drawable/person2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/friendName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Name of friend"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/interactionInPersonIcon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:layout_weight="1"
app:srcCompat="@drawable/in_person" />
<TextView
android:id="@+id/interactionInPersonText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="299"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/interactionVideoIcon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:layout_weight="1"
android:tint="#292828"
app:srcCompat="@android:drawable/presence_video_online" />
<TextView
android:id="@+id/interactionVideoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="299"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/interactionTextIcon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/text_icon" />
<TextView
android:id="@+id/interactionTextText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="299"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/interactionPhoneIcon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:tint="#353535"
app:srcCompat="@drawable/phone_icon" />
<TextView
android:id="@+id/interactionPhoneText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="299"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
ユーザーはテキスト (名前) をテキスト フィールドに入力し、ボタンを押して新しいカスタム ビュー (フレンド リスト内のフレンド) を作成します。
私がやろうとしているのは、ビューに埋め込まれている友人名のテキスト ビューにアクセスすることです。IDは「@id+/friendName」ですが、これにアクセスする方法がわかりません。
したがって、問題は、FriendView 要素の ID がわかっている場合、その中の friendName TextView 要素を取得するにはどうすればよいかということだと思います。
また、別のカスタム ビューが作成されると (新しいフレンド)、各カスタム ビュー内に埋め込まれたビューのこれらの ID が同じになるという問題もあります。唯一の違いは、カスタム ビュー ID が異なることです。これらは実行時にランダムに生成されますか?
とにかく、この埋め込みビューを ID で取得することは、実際には最善の方法ではないのでしょうか?
事前にご協力いただきありがとうございます。