2011-10-14 4 views
3

레이아웃에 TextView가 포함되어 있다고 가정합니다.XML에 레이아웃을 포함하도록 데이터를 할당하는 방법은 무엇입니까?

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView android:id="@+id/text1" 
    style="@style/text_style"/> 

</LinearLayout> 

그런 다음이 레이아웃을 여러 번 포함합니다.

<include android:id="@+id/info1" layout="@layout/myLayout" /> 
<include android:id="@+id/info2" layout="@layout/myLayout" /> 
<include android:id="@+id/info3" layout="@layout/myLayout" /> 

이러한 레이아웃을 포함하는 XML 파일의 각 TextView에 텍스트를 할당 할 수 있습니까?
그렇지 않다면 런타임에 할당하는 방법은?

답변

1

는이를 위해 당신은 당신이

TextView text1 = (TextView)info1.findViewById(R.id.text1); 
text1.setText("Your text"); 
+0

멋진 텍스트 뷰 당신이 확인해야이 레이아웃 객체와 그 다음

LinearLayout info1 = (LinearLayout)findViewById(R.id.info1); 

레이아웃 식별해야합니다! 레이아웃을 단순화 할 때 유용합니다. – thecr0w

관련 문제