MvxSpinner
以设置默认值
“ 选择一个值 ”。如何以优雅的方式实现这一目标
XML
<Mvx.MvxSpinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:background="@drawable/dropdown"
local:MvxBind="ItemsSource Cruise; SelectedItem CruiseLineSelected; Visible CruiseAndShipSelectionVisibility"
local:MvxItemTemplate="@layout/spinner_cruise_list"
local:MvxDropDownItemTemplate="@layout/spinner_cruise_list"
android:text="Select a cruise"
android:layout_marginBottom="20dp"
android:id="@+id/mvxSpinnerCruise" />
答案 0 :(得分:0)
我找到一个简单的解决方案来设置Mvvm
的默认文本并且它工作正常,我认为您可以使用 public class MySpinnerAdapter<T> : ArrayAdapter<T>
{
private Context mContext;
private int mTextResourceId;
public MySpinnerAdapter(Context context, int textViewResourceId):base(context,textViewResourceId)
{
mContext = Context;
mTextResourceId = textViewResourceId;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = base.GetView(position, convertView, parent);
if (position == Count)
{
TextView a = (view.FindViewById<TextView>(Android.Resource.Id.Text1));
a.Text = "";
TextView b = (view.FindViewById<TextView>(Android.Resource.Id.Text1));
b.Hint = GetItem(Count).ToString(); //"Hint to be displayed"
}
return view;
}
public override int Count => (base.Count - 1);
}
自己实现此功能,这里是
代码:
spinner = FindViewById<Spinner>(Resource.Id.spinner);
var adapter = new MySpinnerAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
adapter.Add("php");
adapter.Add("java");
adapter.Add("C++");
adapter.Add("C");
adapter.Add("Select a cruise");
spinner.Adapter = adapter;
spinner.SetSelection(adapter.Count); //display hint
使用时:
Spinner
Here是$this->getDataSource()->config['database']
。