I'm looking to set an different image for a each marker using a drawable resource image.
What I have is this.
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
TextView tv1 = (TextView) v.findViewById(R.id.tv1);
TextView tv2 = (TextView) v.findViewById(R.id.tv2);
Button btn = (Button) findViewById(R.id.button);
LatLng pos = marker.getPosition();
tv1.setText(marker.getTitle());
tv2.setText(marker.getSnippet());
ImageView image = ((ImageView) findViewById(R.id.image42));
return v;
}
This sets the image for a marker but I want it to be a different image for each marker.
I was thinking about an if/else statement like this..
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
TextView tv1 = (TextView) v.findViewById(R.id.tv1);
TextView tv2 = (TextView) v.findViewById(R.id.tv2);
Button btn = (Button) findViewById(R.id.button);
LatLng pos = marker.getPosition();
tv1.setText(marker.getTitle());
tv2.setText(marker.getSnippet());
ImageView image = ((ImageView) findViewById(R.id.image42));
if (marker == OldMellifontAbbey){
image= image.setBackground(BitmapDescriptorFactory.fromResource(R.drawable.oldmellifont));
}
else{
}
return v;
}
});
Any suggestions are more then welcome. Thanks.
Okay so I think I'm on to something but I still can't figure it out. My edited code is below.
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
TextView tv1 = (TextView) v.findViewById(R.id.tv1);
TextView tv2 = (TextView) v.findViewById(R.id.tv2);
Button btn = (Button) findViewById(R.id.button);
LatLng pos = marker.getPosition();
tv1.setText(marker.getTitle());
tv2.setText(marker.getSnippet());
ImageView image = ((ImageView) findViewById(R.id.image42));
try{
Drawable drawable = getResources().getDrawable(R.drawable.oldmellifont);
image.setBackground(drawable);
}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Hairy ball sack!!!", Toast.LENGTH_LONG).show();
}
return v;
}
});