[英]How to use map in every item of my recycler view
I'm using recyclerview for my android application which each item contains a map. 我正在为我的android应用程序使用recyclerview,其中每个项目都包含一张地图。
my question is how to implement this ? 我的问题是如何实施?
I tried two ways to implement this(fragment and mapview). 我尝试了两种方法来实现此目的(片段和mapview)。 The first way was using fragment in XML file and SupportMapFragment in my java class. 第一种方法是在XML文件中使用片段,并在我的java类中使用SupportMapFragment。 By this method of implementation I got this error: 通过这种实现方法,我得到了这个错误:
android.view.InflateException: Binary XML file line #23: Error inflating class fragment
But when I used MapView I got a white view and nothing else :| 但是当我使用MapView时,我得到了一个白色的视图,而没有其他东西:|
I implemented fragment this like 我实现了像这样的片段
HERE IS XML FILE 这里是XML文件
<fragment
android:id="@+id/all_order_each_item_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/_4sdp"
tools:context=".AllOrdersActivity"/>
HERE IS HOW I INITIALIZE MAP IN MY JAVA CLASS 这是我如何在JAVA班级中初始化地图
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.all_order_each_item_map);
mapFragment.getMapAsync(this);
Then I used mapView as my second way this like HERE IS XML FILE 然后,我将mapView作为第二种方式,例如HERE IS XML FILE
<com.google.android.gms.maps.MapView
android:id="@+id/all_order_each_item_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/_4sdp"/>
CODE BELOW SHOWS HOW I INITIALIZE MAPVIEW IN MY JAVA CLASS 下面的代码显示如何在我的JAVA类中初始化MAPVIEW
mapFragment = viewHolder.root_view.findViewById(R.id.all_order_each_item_map);
I used this library ( https://github.com/lisawray/groupie ) as my recyclerview adapter 我使用这个库( https://github.com/lisawray/groupie )作为我的recyclerview适配器
In advance, I apologize for language mistakes and any other problems. 事先,对于语言错误和任何其他问题,我深表歉意。
THANKS 谢谢
我终于找到了答案,方法是从此解决方案获得帮助https://stackoverflow.com/a/30484062/10401375并编辑我的代码的某些部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.