Last active
November 20, 2024 03:35
-
-
Save alunsford3/5d7c1bb5a67b90b4e1f3 to your computer and use it in GitHub Desktop.
RecyclerViews with MapViews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<merge xmlns:android="http://schemas.android.com/apk/res/android"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="@string/text" | |
android:textSize="24sp" | |
android:padding="5dp"/> | |
<com.google.android.gms.maps.MapView | |
android:id="@+id/list_item_map_view_mapview" | |
android:layout_width="match_parent" | |
android:layout_height="100dp" | |
android:layout_weight="1"/> | |
</merge> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapViewHolder extends RecyclerView.ViewHolder { | |
private MapViewListItemView mMapViewListItemView; | |
public MapViewHolder(MapViewListItemView mapViewListItemView) { | |
super(mapViewListItemView); | |
mMapViewListItemView = mapViewListItemView; | |
} | |
public void mapViewListItemViewOnCreate(Bundle savedInstanceState) { | |
if (mMapViewListItemView != null) { | |
mMapViewListItemView.mapViewOnCreate(savedInstanceState); | |
} | |
} | |
public void mapViewListItemViewOnResume() { | |
if (mMapViewListItemView != null) { | |
mMapViewListItemView.mapViewOnResume(); | |
} | |
} | |
public void mapViewListItemViewOnPause() { | |
if (mMapViewListItemView != null) { | |
mMapViewListItemView.mapViewOnPause(); | |
} | |
} | |
public void mapViewListItemViewOnDestroy() { | |
if (mMapViewListItemView != null) { | |
mMapViewListItemView.mapViewOnDestroy(); | |
} | |
} | |
public void mapViewListItemViewOnLowMemory() { | |
if (mMapViewListItemView != null) { | |
mMapViewListItemView.mapViewOnLowMemory(); | |
} | |
} | |
public void mapViewListItemViewOnSaveInstanceState(Bundle outState) { | |
if (mMapViewListItemView != null) { | |
mMapViewListItemView.mapViewOnSaveInstanceState(outState); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapViewListItemView extends LinearLayout { | |
protected MapView mMapView; | |
public MapViewListItemView(Context context) { | |
this(context, null); | |
} | |
public MapViewListItemView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
setupView(); | |
} | |
private void setupView() { | |
View view = LayoutInflater.from(getContext()).inflate(R.layout.list_item_map_view, this); | |
mMapView = (MapView) view.findViewById(R.id.list_item_map_view_mapview); | |
setOrientation(VERTICAL); | |
} | |
public void mapViewOnCreate(Bundle savedInstanceState) { | |
if (mMapView != null) { | |
mMapView.onCreate(savedInstanceState); | |
} | |
} | |
public void mapViewOnResume() { | |
if (mMapView != null) { | |
mMapView.onResume(); | |
} | |
} | |
public void mapViewOnPause() { | |
if (mMapView != null) { | |
mMapView.onPause(); | |
} | |
} | |
public void mapViewOnDestroy() { | |
if (mMapView != null) { | |
mMapView.onDestroy(); | |
} | |
} | |
public void mapViewOnLowMemory() { | |
if (mMapView != null) { | |
mMapView.onLowMemory(); | |
} | |
} | |
public void mapViewOnSaveInstanceState(Bundle outState) { | |
if (mMapView != null) { | |
mMapView.onSaveInstanceState(outState); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class RecyclerViewMapViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |
@Override | |
public int getItemCount() { | |
return 10; | |
} | |
@Override | |
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
MapViewListItemView mapViewListItemView = new MapViewListItemView(getActivity()); | |
mapViewListItemView.mapViewOnCreate(null); | |
mMapViewListItemViews.add(mapViewListItemView); | |
return new MapViewHolder(mapViewListItemView); | |
} | |
@Override | |
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { | |
MapViewHolder mapViewHolder = (MapViewHolder) holder; | |
mapViewHolder.mapViewListItemViewOnResume(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for files, do you know how to handle mapview lifecycle inside the adapter and using onPause on Resume etc... ?