0

I'm trying to add a button after ListView in a custom Dialog using addFooterView() method. birthday_friend_contact_dialog.xml code..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:layout_height="wrap_content" >

<ListView
    android:id="@+id/friend_contact_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp" />

birthday_footerview_button.xml..

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/birthday_friend_footer_button"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content" >

<Button
    android:id="@+id/cancel_contact_dialog"
    android:layout_width="90dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:text="Cancel" />

adding Button in custom Dialog below ListView using the following code..

                final Dialog dialog = new Dialog(AddNewFriend.this);
            dialog.setContentView(R.layout.birthday_friend_contact_dialog);
            dialog.setTitle("Select Contact...");

            ListView contactList = (ListView) dialog
                    .findViewById(R.id.friend_contact_list);

            //////Some code for listview adapter

            View footerLayout = (View)dialog.getLayoutInflater().inflate(R.layout.birthday_footerview_button,null);
            Button dialogButton = (Button) footerLayout
                    .findViewById(R.id.cancel_contact_dialog);
            contactList.addFooterView(footerLayout);

            dialog.show();

But Button doesn't appear below ListView. Thanks in advance.

user3384985
  • 2,975
  • 6
  • 26
  • 42
  • This seems to be an issue with list view height, mostly, listviews have issues with wrap content. Try to set fix height or set it's height to match parent. – Keyfe Ang Sep 12 '14 at 06:27
  • how can i set `ListView` height as a percentage of total screen height? – user3384985 Sep 12 '14 at 06:30
  • Set android:layout_height="match_parent" if you want to set it's height same as its parent. But if you want to it's height as percentage of the screen height, Then you can programatically sets its height(http://stackoverflow.com/questions/2963152/android-how-to-resize-a-custom-view-programmatically) – Keyfe Ang Sep 12 '14 at 06:35

1 Answers1

1

Finally got a solution

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:layout_height="match_parent" >

<EditText android:id="@+id/friend_search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:hint="Search contact.."
    android:inputType="textVisiblePassword"/>

<Button
    android:id="@+id/cancel_contact_dialog"
    android:layout_width="90dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:layout_centerInParent="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="20dp"
    android:text="Cancel" />

<ListView
    android:id="@+id/friend_contact_list"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/friend_search"
    android:layout_above="@id/cancel_contact_dialog"
    android:dividerHeight="1dp" />

user3384985
  • 2,975
  • 6
  • 26
  • 42