I have implemented InfoWindowAdapter on GoogleMap objected to inflate the view of clicked marker the inflated view is showing perfectly but OnclickListener is not working on button of that view also not even button is being touched.
Actually the situation is when i click on marker the inflated view come in front of map fragment This might be issue that the inflated view is not touched or clicked
Below is my code snippet
MainActivity.java
setContentView(R.layout.activity_map_new);
View view = findViewById(R.id.map);
view.setEnabled(false);
map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(true);
LatLng main = new LatLng(Double.parseDouble("31.5497"), Double.parseDouble("74.3436"));
map.addMarker(new MarkerOptions()
.title("Twitter")
.snippet("tweet:")
.position(main)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
map.setInfoWindowAdapter(new CustomMapAdaptor(getLayoutInflater().inflate(R.layout.activity_test, null)));
CustomMapAdaptor.java
public class CustomMapAdaptor implements InfoWindowAdapter, OnClickListener {
private View view;
private Button btn1;
public CustomMapAdaptor(View v) {
view = v;
}
@Override
public View getInfoContents(Marker marker) {
btn1 = (Button) view.findViewById(R.id.btn1);
Toast.makeText(view.getContext(), "getInfoContent call", Toast.LENGTH_SHORT).show();
btn1.setOnClickListener(this);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(view.getContext(), "Bitches please i am touched", Toast.LENGTH_SHORT).show();
return false;
}
});
return view;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public void onClick(View v) {
Toast.makeText(view.getContext(), "Btn1 also clicked", Toast.LENGTH_SHORT).show();
}
}