问题
So the problem is I need to create a screen where I have a map and a list under it , but to have a map I have a :
public class MyMapActivity extends MapActivity{}
to have a list i have :
class MyListActivity extends ListActivity{}
since there is no multiple inheritance ,what is the correct way to do this? Does Android have any Interface for this ? How would you do this?
So i did it like this:
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)));
with the layout xml like this
<?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>
but it keep dying any ideea how to start debugging i'm a bit new to Android development
回答1:
Use only MapActivity.....You can Display listview Without ListActivity ,but Cant Mapview without MapActivity...
public class MyMapActivity extends MapActivity{
}
I mean display listview using
<Listview android:id = "@+id/mylist"..../>
and you get ,
ListView listview =(ListView)findviewByid(R.id.mylist);
listview.setAdapter(youradapter);
来源:https://stackoverflow.com/questions/9749729/multiple-activity-on-screen-of-android