Dig deeper in the ListView documentation... Look into adding a header
view [the method is like ListView.addHeaderView(View) or something..
verify this before using it].. You can use the header view for the +
Add A Place link and then the contents of the List will be the Places.

Hope this helps!
Nick



On Apr 5, 1:36 pm, Simon Donovan <[email protected]> wrote:
> Hi,
>
> I'm trying to recreate the UI screen called 'My Places' that is used
> in the Weather Channel app.  I'd attach a screenshot of it but I'm not
> sure if I can when posting here.  It seems they're using two listviews
> one on top of the other, but I'm not sure for certain.  Could anybody
> confirm this for me?  If they are doing this, how is this done?  I've
> tried to implement this, but without full success.  My top listview
> 'Add a place' 'comes up correctly, but the bottom listview will not
> appear/populate for me?  I shall attach my code so far......
>
> Any help would be greatly appreciated.
>
> Thanks
>
> Simon
>
> header_row.xml
>
> ?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="wrap_content">
>         <ImageView
>         android:id="@+id/icon"
>         android:layout_width="wrap_content"
>         android:layout_height="fill_parent"
>         android:layout_marginRight="6dip"
>         android:src="@drawable/ic_menu_add" />
>         <LinearLayout
>         android:orientation="vertical"
>         android:layout_width="0dip"
>         android:layout_weight="1"
>         android:layout_height="fill_parent">
>          <TextView
>             android:id="@+id/caption"
>             android:layout_width="fill_parent"
>             android:layout_height="0dip"
>             android:layout_weight="1"
>             android:gravity="center_vertical"
>             android:text="Add a place"/>
>         </LinearLayout>
> </LinearLayout>
>
> main.xml
>
> <?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="?android:attr/listPreferredItemHeight"
>     android:padding="6dip">
>         <ListView
>                 android:id="@+id/header"
>                 android:layout_width="wrap_content"
>                 android:layout_height="wrap_content"/>
>         <LinearLayout
>                 android:orientation="vertical"
>                 android:layout_width="fill_parent"
>                 android:layout_height="wrap_content">
>                 <ListView
>                         android:id="@+id/list"
>                         android:layout_width="fill_parent"
>                         android:layout_height="wrap_content"/>
>         </LinearLayout>
> </LinearLayout>
>
> public class ListViewTest extends Activity
> {
>         private static String[] items={"lorem", "ipsum", "dolor",
>                 "sit", "amet", "consectetuer",
>                 "adipiscing", "elit", "morbi",
>                 "vel", "ligula", "vitae",
>                 "arcu", "aliquet", "mollis",
>                 "etiam", "vel", "erat",
>                 "placerat", "ante",
>                 "porttitor", "sodales",
>                 "pellentesque", "augue",
>                 "purus"};
>
>         private ListView Header;
>         private ListView List;
>         private ArrayList<Caption> caption = null;
>         private CaptionAdapter adapter;
>         private ArrayAdapter listAdapter;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState)
>     {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         caption = new ArrayList<Caption>();
>         Caption cap = new Caption();
>         cap.setCaption("Add a place");
>         caption.add(cap);
>
>         this.adapter = new CaptionAdapter(this, R.layout.header_row,
> caption);
>
>         Header = (ListView) findViewById(R.id.header);
>
>         Header.setAdapter(adapter);
>
>         //Log.d("ListViewTest", "caption size is:" + caption.size());
>
>         adapter.notifyDataSetChanged();
>
>         List = (ListView) findViewById(R.id.list);
>
>         listAdapter = new ArrayAdapter<String>(this,
> android.R.layout.simple_list_item_1, items);
>
>         List.setAdapter(listAdapter);
>
>         listAdapter.notifyDataSetChanged();
>
>         //setListAdapter(new ArrayAdapter<String>(this,
>                                 //android.R.layout.simple_list_item_1,
>                                 //items));
>     }
>
>     private class CaptionAdapter extends ArrayAdapter<Caption>
>     {
>         private ArrayList<Caption> caption;
>
>                 public CaptionAdapter(Context context, int textViewResourceId,
> ArrayList<Caption> caption)
>                 {
>                         super(context, textViewResourceId, caption);
>                         this.caption = caption;
>                 }
>
>                 @Override
>             public View getView(int position, View convertView, ViewGroup
> parent)
>             {
>                         View v = convertView;
>
>                         if (v == null)
>             {
>                 LayoutInflater vi =
> (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>                 v = vi.inflate(R.layout.header_row, null);
>             }
>
>                         Caption c = caption.get(position);
>
>                         if (c != null)
>             {
>                                 TextView caption = (TextView) 
> v.findViewById(R.id.caption);
>
>                                 if (caption != null)
>                 {
>
> caption.setText(c.getCaption());
>                 }
>             }
>
>                         return v;
>             }
>
>     }
>
>
>
> }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to