我正在使用Xamarin內置的行視圖SimpleListItemSingleChoice
。如何顯示已檢查項目的內置行視圖?
我想顯示已檢查項目的視圖,但它不起作用。
我ListAdapter得到作爲輸入,具有一個IsChosen屬性,以便它知道對象的列表,其目的應選擇:
public MySproutListAdapter (Activity context, IList<Sprout> mySprouts) : base()
{
this.context = context;
this.sprouts = mySprouts;
}
的GetView()
方法如下:
public override Android.Views.View GetView (int position,
Android.Views.View convertView,
Android.Views.ViewGroup parent)
{
//Try to reuse convertView if it's not null, otherwise inflate it from our item layout
var view = (convertView ??
context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItemSingleChoice, parent, false)) as LinearLayout;
var textLabel = view.FindViewById<TextView>(Android.Resource.Id.Text1);
textLabel.TextFormatted = Html.FromHtml(sprouts[position].sproutText);
//I thought this line would display the view with the correct item's radio
//button selected, but it doesn't seem to.
textLabel.Selected = sprouts[position].IsChosen;
return view;
}
我查看了選定列表視圖的自定義定義,但由於它是內置視圖,我認爲自定義定義必須過於複雜。
如何使內置視圖正確顯示所選項目?
錯誤,提供了工作示例。 –