Place item below listview

3

I need to place an element below a listview.

So far I have a Linearlayout that contains a spinner that is located on a listview. Being in a LinearLayout, it stays fixed and below I have a Listview which moves down and up. So far it's like this:

What I want now is to put the LinearLayout that contains the spinners so that it appears below the listview but is not fixed as it is now, but appears below the last element in the listview.

This is how I now have the layout of this activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.pablo.android.app.acciones_lora_activity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/capaMedida"
    android:orientation="vertical"
    android:background="@drawable/selector_fieldset_background"
    >

    <Space
        android:layout_width="match_parent"
        android:layout_height="25dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerComp1"
            android:entries="@array/compuertasLora"
            android:spinnerStyle="@android:style/Widget.Spinner.DropDown">
            </Spinner>

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerC1"
            android:entries="@array/accionesMedidaLora"
            android:spinnerStyle="@android:style/Widget.Spinner.DropDown">

        </Spinner>

    </LinearLayout>



    <Space
        android:layout_width="match_parent"
        android:layout_height="5dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerComp2"
            android:entries="@array/compuertasLora"
            android:spinnerStyle="@android:style/Widget.Spinner.DropDown">
            </Spinner>

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerC2"
            android:entries="@array/accionesMedidaLora"
            android:spinnerStyle="@android:style/Widget.Spinner.DropDown">

        </Spinner>

    </LinearLayout>

    <Space
        android:layout_width="match_parent"
        android:layout_height="5dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerComp3"
            android:entries="@array/compuertasLora"
            android:spinnerStyle="@android:style/Widget.Spinner.DropDown">
            </Spinner>

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerC3"
            android:entries="@array/accionesMedidaLora"
            android:spinnerStyle="@android:style/Widget.Spinner.DropDown">

        </Spinner>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btn_accionesMedida"
            android:text="Enviar accion"/>

        <android.support.v4.widget.Space
            android:layout_width="5dp"
            android:layout_height="10dp"
            android:id="@+id/espacio"
            android:layout_below="@+id/btn_accionesMedida"/>

    </LinearLayout>
</LinearLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/selector_fieldset_background"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:text="Acciones a medida"
    android:textAppearance="?android:attr/textAppearance"/>

<ListView
    android:id="@+id/mi_lista"
    android:layout_below="@+id/capaMedida"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>
    
asked by Pablo Simon DiEstefano 01.12.2017 в 12:19
source

1 answer

3

There is a method called ListView#addFooterView(view) that add a view to the end of the list.

Create an xml file in the layout folder and add the content of the view you want to add at the end. Then when you initialize the list, you inflate the view and add it with the method addFooterView :

// inflamos la vista que queremos al final
View footer = LayoutInflater.from(context).inflate(R.layout.id_vista, null);

// la agregamos a lista
miListView.addFooterView(footer);

// agregamos los eventos que necesitemos al footer...
// footer.findViewById(R.id.idSpinner).setOnClickListener
    
answered by 01.12.2017 / 13:14
source