template.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_below="@+id/header"
android:orientation="horizontal"
android:id="@+id/template_linear_layout_container"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/template_linear_layout">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/template_title_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ALL"
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Я создал TextView внутри template.xml и я заселена эту линейную компоновку template.xml внутри parent_view с помощью Inflater.Как установить разные тексты в TextViews, заполненные надувом?
for(int i=0;i<3;i++){
View container_template = getLayoutInflater().inflate(R.layout.templates, parent_layout, false);
parent_layout.addView(container_template);
TextView title_tv_template = (TextView) findViewById(R.id.template_title_TV);
title_tv_template.setText(1+i+"text changed ");
}
Я хочу изменить текст каждого заполненного текста, но над кодом изменяется текст только с первого текста.
и 'ID' это число, так как они всегда указывают на тот же идентификатор, то его всегда тот же ресурс (а TextView), который быть целенаправленным. Вам либо нужен идентификатор для каждого разного 'View', либо иметь один экземпляр внутри другого уникального' View' .. так что «mainLayout» с 3 «LinearLayout» (a, b, c), а затем с помощью 'mainLayout. a.title', 'mainLayout.b.title',' mainLayout.c.title' – Bonatti