這裏是我的Prent公司佈局(main.xml中)如何添加另一個佈局編號的時間到我已經創建的LinerLayout?
<!-- ============================================================ -->
<!-- All Employees are added here (added and More then one) -->
<!-- ============================================================ -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<!-- ++++++++ here extra layout is added programmatically -->
</LinearLayout>
這裏是我的,我要爲兒童的另一個佈局文件,說child.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:singleLine="false"
android:maxLines="2"
android:text="hello"/>
<TextView
android:id="@+id/list_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:text="Photos"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btn_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Save" />
</LinearLayout>
現在在我的主要活動我打電話main.xml和基於for循環的條件我想添加child.xml的佈局,並且每次我想設置child.xml的TextView的不同值時
那麼它怎麼可能呢?
我做這樣的:
private void doCalculationForMultipleEmployee() {
singleEmployee.setVisibility(View.GONE);
for (int i = 0; i<=tempEmployerList.size()-1; i++) {
View repeatedLayout = LayoutInflater.from(getApplicationContext()).inflate(R.layout.test);
((TextView)repeatedLayout.findViewById(R.id.list_title)).setText("Employee"+i);
// customize repeatedLayout with other data
myLinearLayout.addChild(repeatedLayout);
}
}
但這樣做,我在.inflate和.addChild
所以我在哪裏出了錯了語法錯誤之後?請通過一些代碼來幫助我通過for循環添加它。
我認爲你應該使用的ListView – 2012-01-11 10:56:39
父也許你需要一個ListView和n一個LinearLayout。在這裏看到更多的信息http://developer.android.com/resources/tutorials/views/hello-listview.html – 2012-01-11 10:57:34
@Samir:請看我更新的問題。 – 2012-01-11 11:03:14