tags:

views:

42

answers:

2

Basically I am trying to recreate the default contact screen when you click on "+" button another row of Phone number added to the list.

Right now I have an ImageView as the "+" button and a ListView to contain the list of phone numbers. The problem is that the ListView doesn't expand when I add more item into the list.

I could build the same look with LinearLayout but how can I save all those numbers that way?

Below is the layout of the item that will be inflate with custom Adapter

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="60px"
  android:stretchColumns="1"
  android:background="#FFFFFFFF"
  android:gravity="center_vertical">
  <TableRow>
    <Button
        android:id="@+id/type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:text="Home" />
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            >   
            <EditText
                android:id="@+id/value"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:text=""
                android:hint="Name"
                android:lines="1"
                android:textSize="10pt"
                android:typeface="sans"
                android:textColor="#FF000000"
                android:gravity="left"
                />
        </RelativeLayout>
    <ImageView
      android:id="@+id/del"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:layout_alignParentTop="true"
      android:paddingRight="14dp"
      android:src="@android:drawable/ic_delete" />
  </TableRow>
</TableLayout>

This is the ListView portion.

<ListView
                  android:id="@+id/phoneList"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:background="#FFFFFFFF"
                  android:scrollbars="none" />

This is really confusing :S. Could anyone help me please?

A: 

You should use a ViewStub.

A ViewStub is an invisible, zero-sized View that can be used to lazily inflate layout resources at runtime. When a ViewStub is made visible, or when inflate() is invoked, the layout resource is inflated.

Here you have some tutorials or you can clone the android's git repo to check how they did it.

Macarse
How can you add more than 1 View to it using ViewStub? Wouldn't it just going to inflate another view with ListView inside?
RobGThai
A: 

I ended up created my own class extending LinearLayout and have its size recalculate every time item is added or removed. I'm sure the code is dirty and takes up lots of memories but it work for now.

RobGThai