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 :

First,  you can create a new XML file that should contain a listView like this for example:

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

Then, in your activity type the following

 setContentView("xmlFile"); 

Here for example, I would like  to put that image within my ListActivity .

Second, 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 : ) .

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s