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

Sunday, June 20, 2010

Changing the background colour or Image of a ListActivity!!

Well ,
I was stuck for like three hours trying to figure out how to change the background of a ListActivity because I have used an adapter with a layout for each item so when I change the background at the layout, only the item's background is changed, but at the end I figured that it was very easy here is how I did it :-

inside your onCreate() preferably before setting any adapters or putting any views, you insert the following line : getListView().setBackgroundResource("your Image"); that did the trick .

Hope it helps!!

Saturday, June 19, 2010

How to Change the Color of an image when Clicked in Android ?

Well ,in advanced mobile applications or normal ones , a developer should communicate with the user using some feed backs so changing the color of an image or label when clicked gives the user the feedback that he has really clicked something, here how it is done :-

In your onClick() method , use the following method :
-setColorFilter("color in hexa" , "mode") , in my case I use
-button.setColorFilter(0x77000000,Mode.SRC_ATOP);

doing this you will change the Colour but if you pressed the back button , you will find it stuck on the colour you changed ,to return things as they were you can either use -setColorFilter(null) or setColorfilter(Color.TRANSPARENT,Mode.SRC_ATOP)

I use setColorFilter(null) and this does the trick for me