onsdag 28 oktober 2009

Using Map and List in the same activity

One of Javas problems (not correct to call it a problem maybe) is the lack of support for multiple inheritance. This means that you cannot extend both for instance MapActivity and ListActivity from the same class. So how do you implement a map with a list then? It's easy!

The ListActivity is nothing more than a wrapper around the ListView. What it does is only making it slightly easier to use a listView but it doesn't give you any extra value.

Instead of using the getListView() of ListActivity you simply fetch your own declared ListView exactly the same way as you fetch any other view

ListView lv = (ListView) findViewById(R.id.my_list_view);

You can then use this in any way you prefer. Put an adapter to it by using setAdapter() instead for ListActivity.setListAdapter() (it does the same thing).

This actually took me a while to figure out since almost all tutorials and the examples always extends the ListActivity instead of using the raw view.

fredag 2 oktober 2009

Localhost settings for Android emulator

Recently I stumbled upon a problem when trying to connect to a local webservice through the Android emulator. Everytime I tried to connect it ended up with a "Connect refused" exception.

The answer to the problem and the solution is simple. What I was trying to do was to connect to "http://localhost:7001/myWebservice". The emulator interprets this as a connect to itself because it sees itself as localhost (of course :) ).

The solution? As Google states in their Android documenatation, http://developer.android.com/guide/developing/tools/emulator.html#emulatornetworking , the emulator runs behind a virtual router/firewall and you can reach the host loopback interface (127.0.0.1) by using the adress 10.0.2.2.

torsdag 1 oktober 2009

SOAP webservices on Android

To be able to consume SOAP ws on your Android phone please follow the simple steps in this blog http://android.amberfog.com/?p=45 .

You also may need to rename HttpConnectionSE to HttpConnection or update the code using your *HttpConnectionSE class instead.