Android 画面の に表示しようとしています。そして、Google Map
を作成しようとしています。Top Half
Bottom Half
List View dynamically
問題文:-
しかし、この以下のプログラムを実行しようとするたびに、私のアプリケーションは常に取得しますforced closed.
そして、私がいつも得る例外は-
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testproject/com.example.testproject.MyTwoListItemsActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView
以下は私のコードです-
public class MyTwoListItemsActivity extends ListActivity {
private ListView mListView;
private MapView mapView;
private MapController mapController;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mListView = (ListView) findViewById(R.id.mylist);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
mapController.setZoom(15);
ArrayList<Map<String, String>> list = buildData();
String[] from = { "name", "purpose" };
int[] to = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, list,
android.R.layout.simple_list_item_2, from, to);
mListView.setAdapter(adapter);
}
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(putData("Android", "Mobile"));
list.add(putData("Windows7", "Windows7"));
list.add(putData("iPhone", "iPhone"));
return list;
}
private HashMap<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", name);
item.put("purpose", purpose);
return item;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
これが私の 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
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:apiKey="0s_fADEBtq0-j_teQ1j-yaoDAivoHHtwN81rJ-g"
android:clickable="true"
android:state_enabled="true" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ListView
android:id="@+id/mylist"
android:layout_width="164dp"
android:layout_height="142dp"
android:layout_weight="0.33" >
</ListView>
</LinearLayout>
</LinearLayout>