Archive for the ‘IS:Android’ Category

Parsing XML in Android (DOM method)

Saturday, April 10th, 2010

This is a simple example parsing twitter xml in Android

Here is the sample tweet data (one entry is one tweet)

Parsing XML with DOM method is an iterative process.
As you can see below, continuously use NodeList and Node object to explore the elements of XML document
In this example, I extracted <name> element under the <author>


Getting GPS location information in Android

Saturday, April 10th, 2010

To get geolocation information, we need to implement LocationListener

public class GPSTesting extends ListActivity implements  LocationListener {


Then, the location information will be delivered by these callback methods

in onCreate method, we can initialize locationManager and bestProvider

We can extract latitude and longitude data from the Location object just like this

mLongitude = location.getLongitude();
mLatitude = location.getLatitude();


I used latitude and longitude data to retrieve nearby twitter users.

By the way, New York is really hot! (…What?)


Adding EditTextPreference

Friday, March 5th, 2010

How to add preference in Android

Create prefs.xml in res/xml folder

You can add EditTextPreference after clicking PreferenceScreen

Now you can define the Key and Tile for the properties.

Then it will generate the xml like this.

Prefs.java – it loads preference from R.xml.prefs (which is generated resources R.java)

And this is menu.xml, including two menu items.


Finally, in the main java file, we can call the menu by these methods.
in onCreateOptionMenu, we are using MenuInflater to populate menu.
And we launch the Prefs class using Intent in onOptionsItemSelected.

When you press the OPTION key (Hard key) you will see the Prefs menu.