1

Usually I would just seperate out the activities but I want to show a screen that has a view text views, a list, and then a map view. I'm not sure how to go about doing that because I know the activity can only extend either listview or mapview.

I have one xml file like this we'll call it the main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relativeLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#ffffff">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tvName"
        android:textColor="@color/dark" android:text="Name"></TextView>
    <EditText android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/etName"></EditText>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/btnAdd"
        android:text="Add location"></Button>
    <ListView android:layout_height="wrap_content"
        android:layout_width="match_parent" android:id="@android:id/list"></ListView>
</LinearLayout>

and another xml file that is just a big map

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <com.google.android.maps.MapView
        android:id="@+id/mapsView" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:clickable="true"
        android:apiKey="myapikey" />

The main activity inflates the first xml sheet with the list, but then how do I add the map to this? Do I nest a class that extends the map activity class and some how add the view? This is what I was thinking

public class AddLocationActivity extends ListActivity{


public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);



}
public class ShowMap extends MapActivity{

            public ShowMap(){

             //maybe get the map.xml and add the view somehow?
             }



    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}

}

2

1 Answer 1

3

Like mkso commented, you do not need to extend from ListActivity to use a ListView, see this for an example (not the best, but what I could find quickly). Just create the layout how you want it, extend from MapActivity and use the ListView by calling findViewById().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.