/ / Wie kann ich eine Ansichtsgruppe dynamisch erstellen? - Java, Android, Listenansicht, Fußzeile, Ansichtsgruppe

Wie erstellt man eine Ansichtsgruppe dynamisch? - Java, Android, Listenansicht, Fußzeile, Viewgroup

Ich habe eine Listenansicht.

Ich möchte eine Fußzeile hinzufügen.

Also erstelle ich eine Fußzeile xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="@drawable/background_news_list"
android:gravity="center" >

<ImageButton
android:id="@+id/btn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:background="@drawable/btn_more_news" />

</LinearLayout>

Ich möchte das gesamte Layout in Java aufblasen, aber ich schaffe es nur, die Schaltfläche aufzublasen

footer = getLayoutInflater().inflate(R.layout.testing, null, false);
btnmore = (ImageButton)footer.findViewById(R.id.btn_more);

ListView lv = (ListView) findViewById(android.R.id.list);
lv.addFooterView(footer);

Meine Liste ist in dieser XML

<LinearLayout
android:id="@+id/layout_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/layout_menu"
android:layout_below="@id/layout_title"
android:orientation="vertical" >

<ListView
android:id="@+android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>

Wie erstelle ich eine Ansichtsgruppe, um diese zu erfüllen und so zu werden?

footer = getLayoutInflater().inflate(R.layout.testing, parent, false);

Damit ich mein eigenes lineares Layout verwenden kann.

Antworten:

0 für die Antwort № 1

Ihr Beitrag ist ein wenig verwirrend, aber ich denke, Sie müssen Ihrem LinearLayout nur eine ID hinzufügen:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/linlayoutid"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="@drawable/background_news_list"
android:gravity="center" >

<ImageButton
android:id="@+id/btn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:background="@drawable/btn_more_news" />

</LinearLayout>

Dann nimm das lineare Layout:

footer = getLayoutInflater().inflate(R.layout.testing, null, false);
LinearLayout ll = footer.findViewById(R.id.linlayoutid);

ListView lv = (ListView) findViewById(android.R.id.list);
lv.addFooterView(ll);

0 für die Antwort № 2

Ich habe es dadurch gelöst

footer = getLayoutInflater().inflate(R.layout.testing, lv, false);

Das ist weil

lv is the list id and it