メイン レイアウトにボタンがあり、onClick 次の方法で別の xml レイアウトを再利用しています。
View view = layoutInflater.inflate(R.layout.single_elemnt,
createLayout, false);
createLayout.addView(view, position);
position++;
ボタン(メインレイアウトにある)がクリックさsingle_elemnt
れるたびに現在のメインレイアウトに追加されるレイアウトです。add
single_elemnt
textview
には、 aと an の2 つのビューがありedittext
ます。クリックするtv = (TextView) findViewById(R.id.tv);
たびに使っています。add
しかし、問題は、onClick にコードを配置したにもかかわらず、tv
常に最初のものを参照していることです。textview
findViewById
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- some other views -->
<Button
android:id="@+id/add"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:paddingTop="10dp"
android:text="Add"
android:textSize="20sp" />
</RelativeLayout>
アクティビティの onClick メソッド
View view = layoutInflater.inflate(R.layout.single_elemnt,
createLayout, false);
createLayout.addView(view, position);
position++;
tv = (TextView)profile.findViewById(R.id.tv);
tv.setText("some text");
私はここで何か悪いことをしていますか? どんな助けでも感謝します。