Mapbox Inflate View on Fragment Mapbox Inflate View on Fragment xml xml

Mapbox Inflate View on Fragment


You are telling about inflation but look at stack trace:

Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.exampleapp-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libmapbox-gl.so" at java.lang.Runtime.loadLibrary(Runtime.java:366) at java.lang.System.loadLibrary(System.java:988) at com.mapbox.mapboxsdk.views.NativeMapView.(NativeMapView.java:42) at com.mapbox.mapboxsdk.views.MapView.initialize(MapView.java:680) at com.mapbox.mapboxsdk.views.MapView.(MapView.java:621)

BTW:

first

u need to decide if u inflate view every time {local variable) or u reuse it (global one)

example:

if(_view==null)    _view = inflater.inflate(..);return _view;

second:

do not call activities or fragment methods like onCreate onPause manually (those used by os to maintain life cycle)

third:

if u use viewpager and nested fragments u need create adapter with child fragment manager

more & more:

keep in mind that to set some data and properties in child fragment viewpager fragment need to laid out

"First: I am inflating it every time, which is usually not a problem (my tabs work with any other fragment I have created, including Google Maps, just not Mapbox) Second: Yes, you do call activity lifecycle methods manually. You have to use onCreate to inflate a view. Third: I have an adapter, I just did not include it here. That is not the issue, my tabs work fine with any other fragment I have created. Lastly: I'm not sure what you're saying, but my fragments work fine in my other tabs.

Please focus on the problem at hand... putting a Mapbox view in a fragment, > regardless of where that fragment is (tab pageviewer or not).. – TangoJLabs"

/** * Called to do initial creation of a fragment.  This is called after * {@link #onAttach(Activity)} and before * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. * * <p>Note that this can be called while the fragment's activity is * still in the process of being created.  As such, you can not rely * on things like the activity's content view hierarchy being initialized * at this point.  If you want to do work once the activity itself is * created, see {@link #onActivityCreated(Bundle)}. * * @param savedInstanceState If the fragment is being re-created from * a previous saved state, this is the state. */public void onCreate(@Nullable Bundle savedInstanceState) {    mCalled = true;}

move this from onCreate of fragment to onViewCreated(View,Bundle)

mv = (MapView) fragmentLayout.findViewById(R.id.mapview);mv.onCreate(savedInstanceState);miniMap = (MapView) fragmentLayout.findViewById(R.id.mini_map);miniMap.onCreate(savedInstanceState);/** * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} * has returned, but before any saved state has been restored in to the view. * This gives subclasses a chance to initialize themselves once * they know their view hierarchy has been completely created.  The fragment's * view hierarchy is not however attached to its parent at this point. * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. * @param savedInstanceState If non-null, this fragment is being re-constructed * from a previous saved state as given here. */public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {}

last word: gradle files

i dont know if your file content contains both gradle files or only app file but those lines shouldnt be in app gradle file - those are top level gradle :

buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.3.0'    }}repositories {    mavenCentral()    jcenter()}

and u should consider to move to newest android app plugin - but i see you are using gms services - so u top gradle file is containing other plugin and those above is omitted

I'm having trouble following the logic of your edits. I don't have an onCreate from which I can move anything

/** inflate fragment  - this will create view */@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    return inflater.inflate(R.layout.fragment_map, container, false);}/** after view is created - set map view */@Overridepublic void onViewCreated(View view, Bundle savedInstanceState) {    super.onViewCreated(view, savedInstanceState);    if(view!=null) {       MapView mv = (MapView) view.findViewById(R.id.mapview);       mv.onCreate(savedInstanceState);    }}

btw i have more concerns on rest of lifecycle methods - fragment could or not retain state so simple putting activity lifecycle methods in fragment method could produce more problems :)

i don't use & know the source implementation of MapView so i cant tell u how to implement this but i can give u a hint to check if fragment is attached to activity before u call any mapview method

@ceph3us -1 everything mentioned in this is wrong, and your grammar can be improved. I don't have an answer to this, I am here with the same question. 1st root view should not be a field, it should be inflated on each call to onCreateView, 2nd those are proper calls, 3rd and the rest are off topic and not helpful to the subject. – HaydenKai

@HaydenKai

  1. first of all pleas specify the SOURCES for you deliberations
  2. why u want to recreate view ? purpose ? to waste resources (like your time to code and user CPU and MEM)? - there where u can afford it or need a fresh one then its ok but in other cases REUSE !!!
  3. the view does not need to be inflated at all, it can be normally created eg by return new LinearLayout(Context) or FrameLayout or any other complex view - this is a developer choice to use xml or java - i prefer not to use xml - i like pure JAVA :)
  4. so at the very end i can say your -1 is empty one for me her

enter image description here


This library looks in heavy development status and might have some problems, which are mentioned on GitHub, especially when you run version 2.2.0.

Try change version to newest stable:

compile 'com.mapbox.mapboxsdk:mapbox-android-sdk:3.0.0'