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 the screen, but I can't seem to do it 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 = null;
private CaptionAdapter adapter;
private ArrayAdapter listAdapter;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
caption = new ArrayList();
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(this, android.R.layout.simple_list_item_1, items);
List.setAdapter(listAdapter);
listAdapter.notifyDataSetChanged();
//setListAdapter(new ArrayAdapter(this,
//android.R.layout.simple_list_item_1,
//items));
}
private class CaptionAdapter extends ArrayAdapter
{
private ArrayList caption;
public CaptionAdapter(Context context, int textViewResourceId, ArrayList 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;
}
}
}