Google Android News Android Forums

PCWorld How-To's and Tips

PCWorld Latest Technology News

Saturday, June 26, 2010

Adding a view within your ListActivity !!

Well ,

I spent some time trying to find out how to put other views in the same place with a ListActivity and I figured out 2 different ways :-

1st: you can create a new xml file that should contain a listView like this for ex,
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black">


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home" />

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false" />



and then setContentView("xmlFile");

Here I want to put that image within my ListActivity .

2nd:
you can either use add a header or a footage view.

most importantly do this before setting any adapters ,

ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.messageinfo, lv, false);
lv.addFooterView(header, null, false);
or
lv.addHeaderView(header,null,false) ;


I hope this helps : ) .

No comments:

Post a Comment