1

I am working on a project which has a custom listview.Since the getView() method of the baseadapter kept being called thrice the number of rows in the listview,someone suggested that i change the width and height of the listview to match_parent.But now the problem is that there is a button below the listview,which is not visible now.How do i make it visible.

The post i was referring to:custom listview adapter getView method being called multiple times, and in no coherent order

my xml file:

<?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"
     >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="LIST OF TASKS" />

<ListView
    android:id="@+id/list_tasks_final"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="50px"
     >

</ListView>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/list_tasks_final"
    android:layout_centerHorizontal="true"
    android:text="SUBMIT JOB"
    android:id="@+id/btnjobsubmit"
     />

</RelativeLayout>

The issue is that the button is not visible now.How to make it visible?

Community
  • 1
  • 1
Achuthan M
  • 187
  • 1
  • 1
  • 12
  • Can you brief little bit more? What's your expected result and current result? Would be easy for us to help you if you post this result diagrammatically. – Yuva Raj Nov 16 '14 at 08:14
  • @YuvaRaj.I want a button below the listview.But since the listview has match_parent , it fills up the entire screen and the button is not visible.I want the button to be visible. – Achuthan M Nov 16 '14 at 08:16

3 Answers3

0

see my code you should wrap your list view in another view LinearLayout for example and set height to that layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LIST OF TASKS" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="300dp">

        <ListView
            android:id="@+id/list_tasks_final"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="50px"
            >
        </ListView>
    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="SUBMIT JOB"
        android:id="@+id/btnjobsubmit"
        />

</LinearLayout>
Mohammad Rahchamani
  • 5,002
  • 1
  • 26
  • 36
0

Instead of using RelativeLayout, you should use LinearLayout. It provides more flexibility in placing different views according to our need.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_gravity="center_horizontal"
    android:text="LIST OF TASKS" />

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

        <ListView
            android:id="@+id/list_tasks_final"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"/>

    </LinearLayout> 

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="SUBMIT JOB"
    android:id="@+id/btnjobsubmit" />

</LinearLayout>
gegobyte
  • 4,945
  • 10
  • 46
  • 76
0

The problem here is that your list is using all the space of the screen (Layout_height=match_parent, layout_width=match_parent) and the button has the attribute layout_below, then it is shown below the entire screen.

To solve this, just remove the attribute layout_below:

android:layout_below="@+id/list_tasks_final"
jiahao
  • 3,373
  • 2
  • 35
  • 36
  • I want the listview to have match parent for width and height.So obviously it will have fill parent property .So how will the button be visible if the listview occupies the entire screen.? – Achuthan M Nov 16 '14 at 09:40