1

在此处输入图像描述

如上所示,我有一个片段活动,它呈现两个片段。在地图片段上,我想实现并显示地图。

由于我们需要扩展 MapActivity,我不确定如何在片段中完成它。

尝试从https://stackoverflow.com/a/10739200/1737771)实施解决方案

package com.m7.nomad;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Window;

public class MapsFragment extends SherlockFragment {
    private static final String KEY_STATE_BUNDLE = "localActivityManagerState";
    private LocalActivityManager mLocalActivityManager;

    protected LocalActivityManager getLocalActivityManager() {
        return mLocalActivityManager;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle state = null;
        if (savedInstanceState != null) {
            state = savedInstanceState.getBundle(KEY_STATE_BUNDLE);
        }

        mLocalActivityManager = new LocalActivityManager(getActivity(), true);
        mLocalActivityManager.dispatchCreate(state);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // This is where you specify you activity class
        Intent i = new Intent(getActivity(), GMapActivity.class);
        Window w = mLocalActivityManager.startActivity("tag", i);
        View currentView = w.getDecorView();
        currentView.setVisibility(View.VISIBLE);
        currentView.setFocusableInTouchMode(true);
        ((ViewGroup) currentView)
                .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        return currentView;

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBundle(KEY_STATE_BUNDLE,
                mLocalActivityManager.saveInstanceState());
    }

    @Override
    public void onResume() {
        super.onResume();
        mLocalActivityManager.dispatchResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mLocalActivityManager.dispatchPause(getActivity().isFinishing());
    }

    @Override
    public void onStop() {
        super.onStop();
        mLocalActivityManager.dispatchStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mLocalActivityManager.dispatchDestroy(getActivity().isFinishing());
    }

}

我应该为附近指定什么

..............
public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // This is where you specify you activity class
        Intent i = new Intent(getActivity(), GMapActivity.class);
        Window w = mLocalActivityManager.startActivity("tag", i);

..................
4

2 回答 2

5

看看刚刚发布的新的Google Maps Android API v2 。它包含对片段的支持(包括支持库)等等。

于 2012-12-03T22:48:20.723 回答
2

片段中的 MapView(Android 4.0 或更高版本)。你调查过这个吗?.. 这也可以帮助你.. https://github.com/commonsguy/cw-android/tree/master/Maps/NooYawkFragments

于 2012-12-03T11:06:18.127 回答