Libathos
Libathos

Reputation: 3364

adding button to ListActivity

I'm developing and android application in which I have created a ListActivity which contains an ImageView and a TextView. There is also the ability to drag and drop those objects so that they can be moved. What I want to do now is to have a button at the bottom of the screen,not the list.

As the user scrolls the button will always stay there. I found this link but when i did what this link suggested no button did appear, and instead i got a huge blank space that takes over a quarter of the screen. Can anyone point me to the right direction?

ok so here is the .xml file that is set to the ListActivity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<DragNDrop.DragNDropListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  </DragNDrop.DragNDropListView>
</LinearLayout>

hopefully it can help

Upvotes: 0

Views: 899

Answers (2)

Uriel Frankel
Uriel Frankel

Reputation: 14622

I think that ListActivity is a bad practice. What you need to do is to is to change the Activity from ListActivity to Activity. In the layout file, do the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_contant"
    android:orientation="horizontal">
 <DragNDrop.DragNDropListView
   android:id="@+id/android:list"
   android:layout_width="fill_parent"
   android:layout_height="wrap_contant">
 </DragNDrop.DragNDropListView>
 <Button 
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"/>
</LinearLayout>

In on create you can get the list reference by doing:

ListView lv = (ListView)findViewById(R.id.list); 

In order to make the button clickable, user OnClickListener

Upvotes: 0

AkashG
AkashG

Reputation: 7888

Your view should be like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<Button 
     android:id="@+id/btn"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:text="Button"
     android:layout_centerHorizontal="true"/>
 <ListView 
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_above="@+id/btn"/>
</RelativeLayout>

Populate the listview with the data and see the button will be on its place though list being scrolled.

Upvotes: 4

Related Questions