xamarin - 如何在 Xamarin 警报对话框中坚持选择
问题描述
我不相信这是重复的问题。我可以保留从对话框返回的选择;问题是,它总是-1。
此对话框正确显示,但未捕获用户的选择:
var dialogView = LayoutInflater.Inflate(Resource.Layout.list_view, null);
Android.App.AlertDialog alertDialog;
var items = new string[] { "A","B","C" };
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
using (var dialog = new Android.App.AlertDialog.Builder(this))
{
dialog.SetTitle("Choose Letter");
dialog.SetMessage("Just Click!");
dialog.SetView(dialogView);
dialog.SetNegativeButton("Cancel", (s, a) => { });
dialog.SetPositiveButton("OK", (s, a) => {
{
if (a.Which!=-1)
//BUT I don't know how to persist the choice
//when I click on one of the letters, it briefly
//shows the choice (the background is briefly grayed
//but the choice doesn't persist
//so when I click OK, a.Which is -1
{
//do things with the choice
}
}});
alertDialog = dialog.Create();
}
dialogView.FindViewById<ListView>(Resource.Id.listview).Adapter = adapter;
alertDialog.Show();
}
这是 axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
我如何 1) 显示用户的选择而不是短暂变灰的行和 2) 我如何坚持该选择?
解决方案
推荐阅读
- javascript - 如何在反应项目中使用“INLINE CSS”更改背景图像的不透明度而不影响图像上的文本
- python - python中每15行数据框的平均值
- javascript - 导航栏元素
- android - Android RecyclerView项目在切换应用后被滑动时为空
- amazon-dynamodb - 当多方的数量可能太小或太大时建模一对多关系
- perl - perl "for" 循环获取服务状态
- visual-studio-code - Visual Studio Code 高亮标记
- r - .json 文件太大,无法在 R 中使用 rjson 打开
- android - 如何在 android studio 中覆盖第三方库类的方法?
- python - 如何在 python 列表中组合所有相关的字典