我试图在自定义类上实现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'吗? –