Issue
I am trying to add some image button in my marker info. Though the buttons are added in the view but i cat not click on them. When I try to click it clicks on the whole view. My code us given below.
MainActivity.java
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RelativeLayout base;
base = (RelativeLayout) findViewById(R.id.base);
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
try {
initilizeMap(); // Loading map
} catch (Exception e) {
Log.d("asdfadfadf", "asdfasdf");
}
googleMap.setMyLocationEnabled(true);
//googleMap.clear();
IconGenerator i = new IconGenerator(getBaseContext());
i.setStyle(IconGenerator.STYLE_BLUE);
Bitmap tt = i.makeIcon("asdf");
LatLng myLocation = new LatLng(22.899171, 89.500186);
Marker myLocMarker = googleMap.addMarker(new MarkerOptions()
.position(myLocation)
.icon(BitmapDescriptorFactory.fromBitmap(tt))
.title("sssss"));
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker mk) {
// TODO Auto-generated method stub
return null;
}
@Override
public View getInfoContents(Marker arg0) {
// TODO Auto-generated method stub
ImageButton set,from,favor;
View view = getLayoutInflater().inflate(R.layout.marker_info,null);
set = (ImageButton) view.findViewById(R.id.imageButtonDestination);
from = (ImageButton) view.findViewById(R.id.imageButtonFrom);
favor = (ImageButton) view.findViewById(R.id.imageButtonFavourite);
set.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("sssssssssssssssss", "sssssssssssssssss");
}
});
return view;
}
});
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap(); // check if map is created successfully or not
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
don't know what to do. Thanks in advance.
Solution
You can't add click listeners to the Marker's InfoWindow
as it's not a real view. But a Bitmap that gets rendered from you layout.
From Google Docs
: https://developers.google.com/maps/documentation/android/marker#info_windows
Note: The info window that is drawn is not a live view. The view is rendered as an image (using
View.draw(Canvas)
) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), callshowInfoWindow()
. Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
Answered By - Emil Adz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.