I am using the following method do set the mapType of a GoogleMap
object named mMap
.
private void setMapType() {
final CharSequence[] MAP_TYPE_ITEMS =
{"Road", "Satellite", "Hybrid"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Set map type");
int checkItem = 0;
builder.setSingleChoiceItems(
MAP_TYPE_ITEMS,
checkItem,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0:
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
break;
case 1:
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
break;
case 3:
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
break;
}
dialog.dismiss();
}
}
);
AlertDialog fMapTypeDialog = builder.create();
fMapTypeDialog.show();
}
What I am trying to do is disable one of the choices, let's say the 1st one (Road). How could I do that?
P.S.1 I read this AlertDialog with single choice list - I need some items nonclickable but I don't understand how could I make it work in my case.
P.S.2 I tried, this solution too: Android: AlertDialog - how to disable certain choices that are not available Nothing happens. All options are enabled.
I answered a pretty similar question here. Basically you can set a listener when a view is added in a given ListView and disable it.
It is possible to do this in a standard AlertDialog, but using a custom list adapter. Perhaps the reason the first link you posted did not work for you is because it is important that the list items are updated prior to the dialog being populated.
Creating your dialog:
The custom adapter:
Basically, you cann't do it, with simple AlertDialog and Builder. What you trying to do, it's exchange your Views during some interaction, but that items doesn't have such behavior.
But it isn't problem to do it with Custom Dialog. Just for Example...