-1

我有一個用於recyclerview的通用視圖持有者類,它在該行內使用MapView,而視圖持有者類正在擴展我的基本視圖持有者抽象類其中有populateData(TO to),我正在初始化我的viewholder類的構造函數中的映射,並將null傳遞給mapview.onCreate(null)。我無法弄清楚如何在自定義視圖持有者類中的mapview.onCreate()中傳遞Bundle

我的類是這個樣子的

public class MyViewHolder extends BaseViewHolder implements OnReadyMapCallBack{ 

    private MapView mapView; 
    public MyViewHolder(View view){ 

     mapView = view.findViewById(R.id.map); 
     mapView.onCreate(null); //here i should pass Bundle instead 


     } 
// this method is declared in parent class abstract class 

@override  
public void populateData(TO to){ 
    mapView.getAsync(this); 
} 
public void onMapReady(GoogleMap googleMap) { 
} 
} 

回答

0

enter image description here您修整這樣的:

Bundle args = new Bundle(); 
    args.putString("key",value); 

    mapView.onCreate(args); 

+0

我還沒有嘗試過這種方法..我會嘗試一定,謝謝你的答覆。我唯一擔心的是我在非活動類中集成地圖視圖的方式是否會導致任何錯誤?因爲mapFragment有其自己的生命週期,我沒有使用生命週期的任何方法。 –

+0

只要按照這個步驟,並按照我提到的方式放置包。如果你實現所有的生命週期方法,你會沒事的! https://developers.google.com/android/reference/com/google/android/gms/maps/MapView.html#onCreate(android.os.Bundle) – TzlilPha

+0

,但它的回收站持有人將使用的時間膨脹recyclerview行,所以我必須在viewholder中配置map的實現本身不在任何片段中。 –

相關問題