Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android MvxSpinner SelectedItem为空,但在平台端,在ItemSource中首先显示选定的_项_Android_Xml_Mvvmcross - Fatal编程技术网

Android MvxSpinner SelectedItem为空,但在平台端,在ItemSource中首先显示选定的_项

Android MvxSpinner SelectedItem为空,但在平台端,在ItemSource中首先显示选定的_项,android,xml,mvvmcross,Android,Xml,Mvvmcross,我有MvxSpinner和按钮,用于重置其所选项目。在平台端,小部件不会像假设的那样显示空值。它接受源代码中的第一项 视图模型: public List<Thing> Protocols { get { return new List<Thing>() { new Thing("PPTP") // new Thing("

我有MvxSpinner和按钮,用于重置其所选项目。在平台端,小部件不会像假设的那样显示空值。它接受源代码中的第一项

视图模型:

    public List<Thing> Protocols
    {
        get
        {
            return new List<Thing>()
            {
                new Thing("PPTP")
            //  new Thing("fake")
            };
        }
    }

    private Thing _selectedProtocol = new Thing("");
    public Thing SelectedProtocol
    {
        get { return _selectedProtocol; }
        set { _selectedProtocol = value; 
            RaisePropertyChanged(() => SelectedProtocol); 
            RaisePropertyChanged(() => IsCountryListEnabled);
            RaisePropertyChanged(() => IsUsernameEnabled);
            RaisePropertyChanged(() => IsPasswordEnabled);
        }
    }


    public bool IsCountryListEnabled 
    {
        get 
        {
            return !IsEmpty(SelectedProtocol) || IsDedicatedServerTypeSelected;
        }
    }

    private bool IsEmpty(Thing thing) 
    {
        return thing == null || IsEmpty(thing.Caption);
    }

    private bool IsEmpty(string str) 
    {
        return str == null || str.Length == 0;
    }
命令更改所有

ChangeServerTypeCommand = new MvxCommand<string>(s =>
    {
        if (s == null) return;
        switch (s.ToLower())
        {
            case "free":
                ServerType = Server.ServerType.Free;
                break;
        // ...
    }
ChangeServerTypeCommand=new MvxCommand(s=>
{
如果(s==null)返回;
开关(s.ToLower())
{
“免费”案例:
ServerType=Server.ServerType.Free;
打破
// ...
}
所有代码都是可访问的,并通过断点进行检查

现在查看(不完整,只有微调器片段和所有父对象)


ItemSpinner.xml
下拉列表:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:background="#ffffff"
    android:foreground="#000000"
    android:textColor="#000000"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    local:MvxBind="Text Caption" />

因此,SelectedProtocol在平台端已经采用了默认的PPTP值,因此我无法在ViewModel中更改它。并且所有的底层列表(如服务器、国家/地区)都未启用,因为它们依赖于彼此的Selected*属性,但协议未被选中。所有微调器都存在相同的问题,但如果我们修复它,将修复所有问题

谢谢

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:background="#fff"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/settings"

            android:visibility="visible">
            <LinearLayout
                android:background="#f8f8f9"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:orientation="vertical"
                    local:MvxBind="Visibility IsDedicatedServerTypeSelected,Converter=MyVisibilityGoneInverted;"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="11dp"
                    android:background="#fff"
                    android:layout_marginTop="2dp">

                    <LinearLayout

                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" >

                        <TextView

                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Countries"
                            android:id="@+id/textView10"
                            android:textColor="#8e8e92"
                            android:textSize="14dp" />

                        <MvxSpinner
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/textView9"
                                android:textColor="#1d1d26"
                                android:layout_marginTop="0dp"
                                android:textSize="14dp"
                                local:MvxItemTemplate="@layout/item_spinner"
                                local:MvxDropDownItemTemplate="@layout/item_spinnerdropdown"
                                local:MvxBind="ItemsSource Countries;SelectedItem SelectedCountry; Enabled IsCountryListEnabled" />
                    </LinearLayout>
                </RelativeLayout>

ItemSpinner.xml
    <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:background="#ffffff"
    android:foreground="#000000"
    android:textColor="#000000"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    local:MvxBind="Text Caption" />
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:background="#ffffff"
    android:foreground="#000000"
    android:textColor="#000000"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    local:MvxBind="Text Caption" />