はここに私の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
で構文エラーを得たことをやった後、だからここで私が間違っていますか?ループのためにいくつかのコードを追加してください。
は、私はあなたがリストビュー –
を使うべきだと思うループを使用し、親におそらくあなたは、ListViewコントロールを必要とn LinearLayoutを使用します。詳細はこちらhttp://developer.android.com/resources/tutorials/views/hello-listview.html –
@Samir:最新の質問をご覧ください。 –