Android - SupportMapFragment with GoogleMaps API 2.0 giving IllegalArgumentException

前端 未结 11 1754
情书的邮戳
情书的邮戳 2020-11-27 04:17

I am trying to use the latest Map API 2.0 provided for Android. I am using the Support Library as I want to support Android 2.2. Following is my code:

Main A

11条回答
  •  眼角桃花
    2020-11-27 04:38

    I was facing the same issue in JakeWhartonViewPagerIndicatore along with SherlockFragments. Here is sample TestFragment with solved issue, thanks to Natalia for providing above solution. Your fragment may be a little different from mine.

    Reference: Making ActionBarSherlock and ViewPagerIndicator play nice

    Good Luck..!!

    package com.example.vpiabstest;
    
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentTransaction;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;
    
    import com.actionbarsherlock.app.SherlockFragment;
    
    public class TestFragment extends SherlockFragment {
        private String mContent = "???";
        private String text;
        private static final String KEY_TAB_NUM = "key.tab.num";
    
        public static TestFragment newInstance(String text) {
            TestFragment fragment = new TestFragment();
    
            // Supply num input as an argument.
            Bundle args = new Bundle();
            args.putString(KEY_TAB_NUM, text);
            fragment.setArguments(args);
    
    
            return fragment;
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            text = getString(R.string.tab_page_num) + mContent;
    
            View view = null;
    
            if(text.contains("2")) {
                view = inflater.inflate(R.layout.pinpoints_list, null);
            } else if(text.contains("1")) {
                view = inflater.inflate(R.layout.main_fragment_activity, null);
            } else {
                view = inflater.inflate(R.layout.activity_main, null);
                ((TextView)view.findViewById(R.id.text)).setText(text);
            }
    
    
            return view;
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mContent =  getArguments() != null ? getArguments().getString(KEY_TAB_NUM) : "???";
        }
    
        public void onDestroyView() {
            super.onDestroyView();
    
            // Your Programing skills goes here
    
            if(text == null || !text.contains("1")) {
                return;
            }
    
            // Do Not Miss this
            try {
                Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_fragment));  
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.remove(fragment);
                ft.commit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

提交回复
热议问题