小编Gir*_*ion的帖子

Android Google在RecyclerView.ViewHolder中映射片段

如何从RecyclerView.ViewHolder访问GoogleMap

我有:

public class MapRowHolder extends RecyclerView.ViewHolder
{
 public MapRowHolder(View view) {
        super(view);
 }
}
Run Code Online (Sandbox Code Playgroud)

XML:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android.support.v7.cardview:cardBackgroundColor="@color/blue"
android.support.v7.cardview:cardCornerRadius="@dimen/card_corner"
android.support.v7.cardview:cardElevation="@dimen/card_elevation">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="right|center_vertical"
    android:gravity="center_vertical|right"
    android:layout_width="fill_parent">


    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:tag="maps"

        android:id="@+id/map_view_fragment" tools:context=".Map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_centerInParent="true"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

适配器:

public class MapAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{


 public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        RecyclerView.ViewHolder mh;


        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_row, viewGroup, false);
        mh = (RecyclerView.ViewHolder)new PodatkiZaMapRowHolder(v);

        return mh;
    }

 public void onBindViewHolder(RecyclerView.ViewHolder RowHolder, int polozaj) {

        MapRowHolder …
Run Code Online (Sandbox Code Playgroud)

android google-maps android-adapter android-fragments android-viewholder

5
推荐指数
1
解决办法
6919
查看次数