-1

I have a custom ListView. This ListView contains Bluetooth Devices found during a Scan. I want to have the possibility to click on one single item (i.e. Bluetooth Device) of the list and at the end of the list I want a Button, that allows me to connect to the selected Device. The problem is that I can't get a single button at the end of the list, but I have a button for each item of the list.

This is my XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".DeviceScanActivity"
tools:ignore="ExtraText">


<ListView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1">

</ListView>

<TextView
    android:id="@+id/device_name"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textSize="20sp" >
</TextView>


<TextView
    android:id="@+id/device_address"
    android:textSize="12sp"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TextView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">

<Button
    android:id="@+id/connectButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Connect"
    android:onClick="ConnectButton"
    android:layout_gravity="center">
</Button>
</LinearLayout>

</RelativeLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • If button will appear after the last item of list then add a footer to your list view . See https://stackoverflow.com/questions/4265228/how-to-add-a-footer-in-listview. If not then add the expected output image in question . – ADM Apr 18 '18 at 15:40
  • 1
    Why are you putting textViews after listView? – Prashant Abdare Apr 18 '18 at 15:56

1 Answers1

0

Why do you only have weight on your ListView and not your other Layout objects?

Try this:

1)Change your parent layout from relative to Linear (Vertical).

2)Nest everything outside of the ListView (Your texts and Button) in another Linear (or any other) layout. Then set both your ListView and other view's height to "0dp". Also add weights to them, based on your preference; I'd say probably something like 6:1 or 7:1 (big numbers for ListView and small number for your other layout containing buttons)

This should show them at the bottom of your ListView

Khash
  • 151
  • 1
  • 12