を解決するための場所を設定
public class EqListAdapter extends RecyclerView.Adapter<EqListAdapter.MyViewHolder>{
Context mContext;
EqData eqData;
View convertView;
public EqListAdapter(Context mContext, EqData eqData) {
this.mContext = mContext;
this.eqData = eqData;
}
@Override
public EqListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
return new MyViewHolder(v);
}
@Override
public void onBindViewHolder(EqListAdapter.MyViewHolder holder, int position) {
final float str = eqData.result.get(position).strength;
final LatLng latlng = new LatLng(eqData.result.get(position).lat,eqData.result.get(position).lon);
final String loc = eqData.result.get(position).location;
final String time = eqData.result.get(position).date;
GoogleMap thismap = holder.gMap;
if (thismap != null){
thismap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 13));
thismap.addMarker(new MarkerOptions().position(latlng));
thismap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
}
});
thismap.getUiSettings().setMapToolbarEnabled(false);
}
holder.locationText.setText(loc);
holder.strText.setText(""+str);
holder.timeText.setText(time);
}
@Override
public void onViewRecycled(MyViewHolder holder) {
super.onViewRecycled(holder);
// Cleanup MapView here?
/* if (holder.gMap != null)
{
holder.gMap.clear();
holder.gMap.setMapType(GoogleMap.MAP_TYPE_NONE);
}
}*/
@Override
public int getItemCount() {
return this.eqData.result.size();
}
class MyViewHolder extends RecyclerView.ViewHolder implements OnMapReadyCallback
{
TextView strText;
TextView locationText;
TextView timeText;
MapView map;
GoogleMap gMap;
MyViewHolder(View itemView) {
super(itemView);
map = (MapView)itemView.findViewById(R.id.mapFragment);
strText = (TextView)itemView.findViewById(R.id.strText);
locationText = (TextView)itemView.findViewById(R.id.locationText);
timeText = (TextView)itemView.findViewById(R.id.timeText);
if (map != null)
{
map.onCreate(null);
map.onResume();
map.getMapAsync(this);
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(mContext);
gMap = googleMap;
}
}
です。ドキュメントで述べたように、BitmapDescriptorFactory
やCameraUpdateFactory
などのクラスを初期化する必要があるため、このメソッドを呼び出す必要があります。しかし
、あなたがMapFragment
やMapView
を使用していて、すでにこれらのクラスのいずれかにgetMapAsync()
を呼び出し、onMapReady(GoogleMap map)
コールバックを待つことによって(非ヌル)Googleマップを取得した場合、あなたは、このクラスを心配する必要はありません。
あなたはGoogle Maps set in lite modeを参照している場合また、あなたはこれらの方法に従うことができます:
- どちらか
MapView
またはMapFragment
- それとも
GoogleMapOptions
オブジェクト内のXML属性としてインテントを使用して、マップビューとライフサイクルイベントを起動できます。Google Maps Android API documentation、
完全対話モードでAPIを使用する場合、MapView
クラスのユーザーは、すべてのアクティビティライフサイクルメソッドをMapView
クラスの対応するメソッドに転送する必要があります。
ライフサイクルイベントを転送し、ライトモードでのMapViewクラス
を使用して、次のような場合を除いて、オプションである:
- そうでなければマップが表示されません、
onCreate()
を呼び出すことが必須です。
- ライトのモードマップにマイロケーションのドットを表示し、デフォルトのロケーションソースを使用する場合は、ロケーションソースがこれらのコール間でのみ更新されるため、
onResume()
とonPause()
に電話する必要があります。独自のロケーションソースを使用する場合、これらの2つのメソッドを呼び出す必要はありません。
サンプルコードhereへのリンクがあります。
最後に、このSO postの解決策をご確認ください。それはまた助けるかもしれない。