Android屏幕上的多项活动?

时间:2012-03-17 11:43:55

标签: android listactivity mapactivity

所以问题是我需要创建一个屏幕,其中有一个地图和一个列表, 但要有一张地图,我有一个:

 public class MyMapActivity extends MapActivity{}

有一个列表我有:

class MyListActivity extends ListActivity{}

因为没有多重继承,这样做的正确方法是什么? Android有这个接口吗? 你会怎么做?

所以我这样做了:

MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);

ListView lv = (ListView)findViewById(R.id.mylist);
lv.setTextFilterEnabled(true);
lv.setAdapter((new ArrayAdapter<String>(this,R.layout.list_item, COUNTRIES)));

布局xml像这样

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="214dp"
    android:apiKey="0FKRDCDlhIYZGYtZdLy5-gDjxF3Q25T7_RIortA"
    android:clickable="true" />

  <ListView
        android:id = "@+id/mylist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

</LinearLay>

但它一直在奄奄一息,如何开始调试我对Android开发有点新鲜

1 个答案:

答案 0 :(得分:4)

仅使用MapActivity .....您可以在没有ListActivity的情况下显示listview,但不使用MapActivity显示Mapview ...

public class MyMapActivity extends MapActivity{

}

我是指使用

显示列表视图
<Listview android:id = "@+id/mylist"..../>

,你明白了,

ListView listview =(ListView)findviewByid(R.id.mylist);  
listview.setAdapter(youradapter);
相关问题