

setOnItemClickListener ( new OnItemClickListener () else if ( tabName. add an onclicklistener to see point on the map Let’s add a listener that when an item is clicked, we set the map to the coordinates of the selected item. Once we have our MapView, we can add a listener to the ListView for selection events. Then, we want to extract our MapView from the XML and set it to a member variable. setAdapter ( new ArrayAdapter ( this, android. List pointsList = new ArrayList () pointsList. empty )) // create some dummy coordinates to add to the list setEmptyView (( TextView ) findViewById ( R. ListView = ( ListView ) findViewById ( R. Next, we want to extract our ListView from the XML, set it to a member variable, and add some initial coordinates to its list adapter. tabhost ) // setup must be called if you are not inflating the tabhost from XML If the user scrolls the list, then the rows and their associated views will be. main ) tabHost = ( TabHost ) findViewById ( android. A ListView typically contains more data than the number of displayed rows. In the onCreate() method, we need to set the content to our XML layout, extract the TabHost object, and call setup() on the TabHost (we need to do this because our Activity is not a TabActivity).

Let’s create a class called TabbedListMapActivity and have it extend MapActivity. As a result of this, we will have to perform the functions of TabActivity ourselves in the MapActivity class (you’ll see that below). Why is this? Using a MapView in Android must be in a MapActivity class, otherwise your app with throw an Exception (take a look at the activities source code if you’re interested in more details). While last tutorial our Activity was of type TabActivity, in this tutorial our Activity has to be of type MapActivity.

Once we have a layout, we need to create our main Activity. Step 1: Create a layoutįirst off, let’s create an XML layout that contains a TabHost, TabWidget, a ListView, and a MapView. So, our goal in this tutorial is to have a list of geo coordinates and when we click on an item in the list, our map view goes to that location. Why again are we using multiple views in an activity instead of using a separate activity for each tab content? Remember, we want our tabs to be able to easily interact with one another, and keeping them as views allows us to handle the logic and interaction within one activity.

In this tutorial, we will up the ante and add a MapView as the content of one of the tabs. Last tutorial, we wrote a simple app that displays two interacting list views in a TabActivity.
