これは、アクション バー タブの MapFragmentと同様の質問ですが、私が理解している明確な回答はありませんでした。私は Android が初めてで、これが開発中の最初のアプリケーションです。
MapFragment
現在、Google マップ v2 用の を作成する MainActivity が 1 つあります。このスクリーンショットに示すように、ActionBar の下にマップを表示します
私の目的は、現在Google マップ v2 用に作成されている Eclipse の MainActivity にタブを実装することです (FragmentActivity
私のアプリケーションのように s またはサポート ライブラリを使用していません)。minSdkVersion=11
MapFragment
MainActivity.java スニペット
public class MainActivityextends Activity
implements LocationListener, LocationSource, OnMarkerClickListener, OnInfoWindowClickListener {
private static GoogleMap googleMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); //Change to Tab mode
....
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/map_fragment" />
</LinearLayout>
map_fragment.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="53.78513542767"
map:cameraTargetLng="-3.14948167651"
map:cameraZoom="14" />
Eclipse は、サポート ライブラリを使用してアクティビティを使用してタブを設定するため、を使用するとエラー (以下) が発生し、MapFragment
タブを使用しない状態に戻りました。その理由はここにあると思います
Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
現在、1 つのページ/アクティビティしか開発されていないため、タブを使用する必要があり、ユーザーとマップにフィルターを表示する方法が必要です。ユーザーは隣接するタブに切り替えてフィルターを編集し、[マップ] タブに戻ってフィルターを選択し、マップ上のマーカーを変更できます。
短い質問ですが、MainActivity.javaのタブを実装する簡単な方法はありますか? これが明確でない場合は、詳細を尋ねてください。ただし、これは私にとって非常に高度です