ogaclejapan / SmartTabLayout

A custom ViewPager title strip which gives continuous feedback to the user when scrolling
Apache License 2.0
7.09k stars 1.34k forks source link

Using Google Maps with SmartTabLayout #77

Closed tibudiyanto closed 8 years ago

tibudiyanto commented 9 years ago

Hi I am trying to use google maps with this library; yet I am receiving this error saying:

Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim'

I know that this means that the library is trying to get a null Fragment. But I dont know how to fix this. Can someone help me?

this is the code:

main activity:

public class MapViewActivity extends AppCompatActivity  {
    private Toolbar toolbar;
    private Activity activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_view);
        activity = this;
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("Activity");
        IconicFontDrawable strips = new IconicFontDrawable(this.getApplicationContext());
        strips.setIcon("fa-bars");
        strips.setIconColor(getResources().getColor(R.color.white));
        int iconSize = Helper.dpToPixel(activity, 20);
        strips.setIntrinsicWidth(iconSize);
        strips.setIntrinsicHeight(iconSize);
        toolbar.setNavigationIcon(strips);
        setSupportActionBar(toolbar);

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getSupportFragmentManager(), FragmentPagerItems.with(this)
                .add("Map", MapViewActivityFragment.class)
                .add("Notification", NotificationFragment.class)
                .add("Pulse", PulseFragment.class)
                .create());

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(adapter);

        SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
        viewPagerTab.setViewPager(viewPager);

    }

Map fragment:

public class MapViewActivityFragment extends SupportMapFragment implements OnMapReadyCallback{
    private GoogleMap googleMap;
    public MapViewActivityFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment_map_view, container, false);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        ft.remove(fragment);
        ft.commit();
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng sf = new LatLng(37.774128, -122.421053);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sf, 15));
    }

XML fragment_map_view:

<LinearLayout
    android:id="@+id/map"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent"
    android:orientation="vertical">
        <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:name="com.gloriovin.helpio.Views.MapViewActivityFragment"
        class="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>

Thanks

ogaclejapan commented 9 years ago

Hi, @theaidorus

Do not work with this?


public class MapViewActivityFragment extends SupportMapFragment implements OnMapReadyCallback{

    private GoogleMap googleMap;

    // public MapViewActivityFragment() {
    // }

    // @Override
    // public View onCreateView(LayoutInflater inflater, ViewGroup container,
    //                          Bundle savedInstanceState) {
    //     super.onCreateView(inflater, container, savedInstanceState);
    //     return inflater.inflate(R.layout.fragment_map_view, container, false);
    // }

    // @Override
    // public void onDestroyView() {
    //     super.onDestroyView();
    //     Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
    //     FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    //     ft.remove(fragment);
    //     ft.commit();
    // }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng sf = new LatLng(37.774128, -122.421053);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sf, 15));
    }
}
ogaclejapan commented 8 years ago

For a long time, there is no response. So, we will close the issue.