我試圖在自定義類上實現android OnMarkerClickListener
,當點擊標記時它將被用作點擊監聽器。Android創建自定義onMarkerClickListener
這是我如何實現它:
首先,我創建一個實現GoogleMap.OnMarkerClickListener
像這樣的自定義類:
public class CustomMarkerClick extends MapsActivity implements GoogleMap.OnMarkerClickListener {
private String mHaoTitle, mHaoDescription;
private Context context;
public CustomMarkerClick(Context context, String haoTitle, String haoDescription) {
this.context = context;
this.mHaoTitle = haoTitle;
this.mHaoDescription = haoDescription;
//I used this to check whether the values are being supplied to the constructor successfully
Toast.makeText(context, haoTitle, Toast.LENGTH_SHORT).show();
}
@Override
public boolean onMarkerClick(Marker marker) {
LinearLayout bottomSheetViewgroup = (LinearLayout) ((Activity)context).findViewById(R.id.design_bottom_sheet_hao);
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetViewgroup);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
TextView tv = (TextView) ((Activity)context).findViewById(R.id.txt_hao_title);
tv.setText(mHaoTitle);
return false;
}
}
這是當一個標記點:
mMap.setOnMarkerClickListener(new CustomMarkerClick(MapsActivity.this, bsHaoName, haoRetriever.getDescription()));
問題是,無論何時我在onMarkerClick
方法中嘗試使用TextView
上的setText
時,文本都不是實際的ly visible。例如,通過構造函數提供的haoTitle字符串在onMarkerCLick
方法中不可見
你嘗試過'infoWindowAdapter'嗎? –