2

このコードを使用して、フラグメントにマップを追加しています。

public class MapFragment : Fragment
{
    private MapActivity map=null;
    public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return new FrameLayout(Activity);
    }

    public override void OnActivityCreated(Bundle savedInstanceState)
    {
        base.OnActivityCreated(savedInstanceState);
        map = new MapView(Activity,"XXXXX-v0jt5Z-XXXXXX");
        //HOW TO ADD THE VIEW HERE???
    }
}

私の質問は、Mono for Androidで、マップをビューに追加する方法です。

注:Javaでは、次のように記述します。

((ViewGroup)getView()).addView(map);

脚注:この例では、Java MapFragmentソースコードのコードを使用しています:https ://github.com/commonsguy/cw-omnibus/blob/master/Maps/NooYawkFragments/src/com/commonsware/android/mapfrags/MapFragment.java

4

1 に答える 1

0

マップをそのままフラグメントに追加することはできません。ホスティング環境が必要です。

MapFragmentのソリューションは次のとおりです。

namespace BahaiResearch.com
{
public class MyMapFragment : Fragment
{
    // FROM http://stackoverflow.com/questions/5109336/mapview-in-a-fragment-honeycomb
    private static  String KEY_STATE_BUNDLE = "localActivityManagerState";

    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        Bundle state = null;
        if (savedInstanceState != null) {
            state = savedInstanceState.GetBundle(KEY_STATE_BUNDLE);
        }
        mLocalActivityManager = new LocalActivityManager(Activity, true);
        mLocalActivityManager.DispatchCreate(state);
    }

    public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        //This is where you specify you activity class
        Intent i = new Intent(Activity, typeof(SteamLocationMapActivity)); 
        Window w = mLocalActivityManager.StartActivity("tag", i); 
        View currentView=w.DecorView; 
        currentView.Visibility = ViewStates.Visible; 
        currentView.FocusableInTouchMode = true; 
        ((ViewGroup) currentView).DescendantFocusability = DescendantFocusability.AfterDescendants;
        return currentView;
    }

    private LocalActivityManager mLocalActivityManager;
    protected LocalActivityManager GetLocalActivityManager() {
        return mLocalActivityManager;
    }   


    public override void OnSaveInstanceState(Bundle outState)
    {
        base.OnSaveInstanceState(outState);
        outState.PutBundle(KEY_STATE_BUNDLE,mLocalActivityManager.SaveInstanceState());
    }

    public override void OnResume()
    {
        base.OnResume();
        mLocalActivityManager.DispatchResume();

    }

    public override void OnPause()
    {
        base.OnPause();
        mLocalActivityManager.DispatchPause(Activity.IsFinishing);
    }

    public override void OnStop()
    {
        base.OnStop();
        mLocalActivityManager.DispatchStop();
    }
}
} 
于 2012-10-02T17:41:09.613 に答える