나는 당신이 찾고있는 방법이 자신의 목록을 만들고 채우는 것이라고 생각합니다.
- 기본 레이아웃 (mainLayout.xml) 만들기 // 적어도 하나 이상의 선형 레이아웃이 있어야합니다.
- 목록 행에 대한 템플릿 레이아웃을 만듭니다.
- 액티비티에서 for 루프를 사용하여 템플릿을 부 풀린 다음 템플릿을 채우고 주 레이아웃에 추가하십시오. 여기
는
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="@+id/listLayout"
android:clickable="true"
>
<TextView android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="3dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop ="true"
android:id="@+id/mainText"
android:text="TextView">
</TextView>
</RelativeLayout>
및 활동에 listtemplate.xml,
public void CreateAndAppendListLayout()
{
List<String> mainList; //populate it...
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
LayoutInflater li = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < mainList.size(); i++){
View tempView = li.inflate(R.layout.listtemplate, null);
TextView textMain = (TextView) tempView.findViewById(R.id.mainText);
textMain.setText(mainList.get(i));
mainLayout.addView(tempView);
}
}
그러나이'ListView'를 사용하지 않는, 예입니다 –