Google Map Lite in CardView

I am trying to get a very basic application that will play with Material Design. I am trying to create a Listview (using the new RecyclerView) as each item is a map that has Google Maps Lite in it.

I basically stuck with this example: Creating lists and cards , for implementing Google Maps I used this example

Every thing “Works” when I have only one element in the adapter (so there is only one element to display) but when I add the second element to the adapter (so there should be two elements in the list), the application crashes:

21158-21158/lollipop.auxilium.nl.lollipoptest E/AndroidRuntime﹕ FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #21: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at lollipop.auxilium.nl.lollipoptest.MyAdapter.onCreateViewHolder(MyAdapter.java:63) at lollipop.auxilium.nl.lollipoptest.MyAdapter.onCreateViewHolder(MyAdapter.java:25) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:4121) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3431) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1810) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1306) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:523) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1988) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2237) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531) at android.widget.LinearLayout.onLayout(LinearLayout.java:1440) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531) at android.widget.LinearLayout.onLayout(LinearLayout.java:1440) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:15204) at android.view.ViewGroup.layout(ViewGroup.java:4793) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2260) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2007) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791) at android.view.Choreographer.doCallbacks(Choreographer.java:591) at android.view.Choreographer.doFrame(Choreographer.java:561) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang. 

Can someone tell me what I am doing wrong?

Besides the error, I can’t understand what would be the best way to set properties on separate cards (in the center, etc.). Help in this area will also be appreciated.

Implementation for reference:

Activities

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.main_recycler_view); mLayoutManager = new LinearLayoutManager(context); mRecyclerView.setLayoutManager(mLayoutManager); ArrayList<String> data = new ArrayList<>(); data.add("Toeter"); mAdapter = new MyAdapter(data, getChildFragmentManager()); mRecyclerView.setAdapter(mAdapter); return rootView; } 

Myadapter

 @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.card, parent, false); ViewHolder vh = new ViewHolder(v); return vh; } 

ViewHolder

 public static class ViewHolder extends RecyclerView.ViewHolder { public ViewHolder(View v) { super(v); } } 
+5
source share
2 answers

Try using MapView instead of MapFragment:

item.xml:

 <android.support.v7.widget.CardView android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="match_parent" app:cardCornerRadius="4dp"> <com.google.android.gms.maps.MapView android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="148dp" app:liteMode="true" app:mapType="normal" /> </android.support.v7.widget.CardView> 

RecyclerAdapter.java:

 public ViewHolder(View itemView) { super(itemView); mapView = (MapView) itemView.findViewById(R.id.map_view); } @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.mapView.onCreate(null); holder.mapView.getMapAsync(this); } 

Remember to implement OnMapReadyCallback in the RecyclerView.Adapter .

Simone

+14
source

Try adding fragments at runtime using the new MapFragment (), etc. I often came across this error when I inflated a map fragment more than once from the same layout. Weird question...

+1
source

Source: https://habr.com/ru/post/1208802/


All Articles