geo*_*geo 5 android android-alertdialog
我正在使用以下方法设置GoogleMap名为 的对象的mapType 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();
}
Run Code Online (Sandbox Code Playgroud)
我想做的是禁用其中一个选项,比如说第一个(道路)。我怎么能这么做呢?
PS1 我读了这个带有单选列表的 AlertDialog - 我需要一些不可点击的项目,但我不明白如何让它在我的情况下工作。
PS2我尝试过,这个解决方案也是:Android:AlertDialog - 如何禁用某些不可用的选择 什么也没有发生。所有选项均已启用。
基本上,你不能用简单的 AlertDialog 和 Builder 来做到这一点。您想要做的,是在某些交互过程中交换您的视图,但该项目没有这样的行为。
但使用自定义对话框来做到这一点没有问题。仅举个例子...
// create a Dialog component
final Dialog dialog = new Dialog(context);
//Tell the Dialog to use the dialog.xml as it's layout description
// With your own Layouts and CheckBoxs
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Android Custom Dialog Box");
TextView headerTextView = (TextView) dialog.findViewById(R.id.txt);
headerTextView .setText("This is an Android custom Dialog Box Example! Enjoy!");
Button dialogButton1 = (Button) dialog.findViewById(R.id.dialogButton1);
dialogButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialogButton1.setEnabled(false);
dialog.dismiss();
}
});
// And so on, with other buttons
dialog.show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8114 次 |
| 最近记录: |