I am working on android with google map marker, look at the images below
I want to change the color of Y & N according to the response, like if it is Y I want the color should be GREEN & if it is N then the color should be RED.
Right now both Y & N are having RED color because I have written following code:
<TextView
android:id="@+id/response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/response_lbl"
android:textAllCaps="true"
android:textColor="@color/event_response_s"
android:textSize="18sp" />
Where event_response_s = RED.
I tried this by removing the android:textColor="@color/event_response_s"
xml code.
if (marker.getSnippet().equals(currentEvent.getButton_one())) {
response.setTextColor(context.getResources().getColor(R.color.green));
}
else response.setTextColor(context.getResources().getColor(R.color.red));
Value of marker.getSnippet() is either Y or N, depends on the button user will press. I want to check this with currentEvent.getButton_one();, which gives value of 1st button. Problem here is I am getting correct value of currentEvent.getButton_one() in other class where it is declared but not in other class i.e. CustomInfoWindow. Final condition should check like this: if Y == Y ---> GREEN else RED.
Please let me know if you need more information or to know what else I have tried.
In Event.java:
Intent i = new Intent(getApplicationContext(), MyActivity.class);
i.putExtra("response1", currentEvent.getButton_one());
In MainActivity.java:
String response_1 = getIntent().getStringExtra("response1");
Now from MyActivity.java I have to use response_1 in CustomInfoWinidow.java for comparison:
if (marker.getSnippet().equals(response_1)) {
response.setTextColor(context.getResources().getColor(R.color.green));
} else
response.setTextColor(context.getResources().getColor(R.color.red));
}
Edit: Try passing in response_1 into the constructor of
CustomInfoWindow
Then in MainActivity.java, pass in
response_1
when you create theCustomInfoWindow
:Original answer:
I got it to work using a combination of a
InfoWindowAdapter
and aMarkerClickListener
.Basically, you need to set the text color of the snippet in the
InfoWindowAdapter
, and set the color of theMarker
in theMarkerClickListener
Result:
the condition:
ain't right it must be:
and make sure that the event will only occurs when the marker is clicked. hope this will help you