【问题标题】:MvxSpinner Blank on Android 4.0 OnlyMvxSpinner Blank 仅适用于 Android 4.0
【发布时间】:2014-02-07 09:54:19
【问题描述】:

我有一个自定义绑定的 MvxSpinner,它与我的 Android 和 iOS 应用程序之间共享的 ViewModel 配合得很好。在 Android API 级别 15 (4.0.3) 及更高版本上,一切看起来都很棒,但在 Android API 级别 14 (4.0) 上,微调器为每个 ListItem 元素显示空白文本。 ListItems 在那里,但 Text 只是空白。当我在 Android 4.0 上进行选择时,正确的值将传递回所选项目的 ViewModel,并且我的应用程序会相应更新。

Android 4.0 上的 MxvSpinner 是否存在任何已知错误?

这是我的 MvxSpinner 的 XML:

<MvxSpinner
        style="@style/spinner_input"
        local:MvxItemTemplate="@layout/item_spinner"
        local:MvxDropDownItemTemplate="@layout/item_spinnerdropdown"
        local:MvxBind="ItemsSource ProductCategoryOptions; SelectedItem SelectedProductCategory" />

这是我的模板:

item_spinner

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/black"
    android:text="Test"
    local:MvxBind="Text Caption" />

Item_SpinnerDropDown

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    local:MvxBind="Text Caption" />

【问题讨论】:

    标签: android xamarin.android xamarin mvvmcross


    【解决方案1】:

    由于此问题尚未标记为已回答,而且我不知道是否已找到答案,因此我发布我的解决方案以供将来的读者参考。

    将以下代码放入名为LinkerPleaseInclude.cs的文件中:

    public void Include(CheckedTextView checkedText)
    {
        checkedText.TextChanged += (sender, args) => checkedText.Text = string.Empty + checkedText.Text;
        checkedText.Hint = string.Empty + checkedText.Hint;
    }
    

    这是链接器包含CheckTextView 绑定所必需的。这适用于 Android API 16 v4.1.x,在 VS2013 中启用了“仅 Sdk 程序集”链接。

    【讨论】:

    • 谢谢 - 我遇到了完全相同的问题 - 在调试中看起来不错,但在发布时文本为空白。你的解决方案奏效了。
    • 我遇到了同样的问题。您的解决方案非常好。谢谢。
    【解决方案2】:

    Android 4.0 上的 MvvmCross 和自定义绑定是否存在任何已知错误?

    我不知道 - 但我承认我没有在 4.0 上进行太多测试 - 我当前的模拟器集包括 2.3.6、4.0.3、4.1 和 4.4.2

    (我也不确定你为什么称之为“自定义绑定”——我假设这只是使用标准 MvxBinding 而不是任何添加/自定义)

    Mvx 目前正在围绕 Android 4+ 和 4.4 中的MvxSpinner/MvxListView 激活和通货膨胀变化跟踪一些错误/问题 - 但这些都不在“不可见”区域 - 请参阅:

    恐怕这不是您的问题/问题的答案。可能值得尝试在您的 Android v4.0 配置中使用不同的颜色和布局,并可能使用层次结构查看器来检查显示的 UI。在这里查看问题,有很多关于 4.0 中微调器可见性的 cmets(但我看不到任何立即有用的东西)-https://stackoverflow.com/search?q=spinner+4.0

    【讨论】:

    • 感谢您的参考。我在设备/模拟器中得到不一致的结果。如果我使用 Xamarin 构建并在模拟器中调试,则文本会出现在下拉菜单的弹出窗口中,但如果我通过 TestFlight 构建和部署,则不会出现文本。如果它可以被调试并且使用特定部署场景的一个版本的 Android 不是问题,那就不会那么糟糕了。如果我发现这是与控件相关的任何类型的问题,我会在此处发布。
    【解决方案3】:

    这似乎是 CheckedTextView 对象上的 local:MvxBind="Text Caption" 属性没有正确更新的问题。

    我将我的 Item_SpinnerDropDown.xml 更改为以下内容(“CheckedTextView”为“TextView”),现在一切正常:

    <?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/WIRECOWEBMOB.Droid"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/black"
    local:MvxBind="Text Caption" />
    

    这不是下拉菜单的首选功能(缺少 Checked 可见性),但它现在适用于所有构建。

    另一个注意事项:我发现这是发布版本的问题,而不是特定的 Android 版本。我在调试模式下使用所有 SDK 版本,它们在我的模拟器中运行良好,但是一旦我切换到 Release,就会出现空白下拉项。

    【讨论】:

      【解决方案4】:

      不确定是否相关,但它帮助了我。

      我正在绑定到我的 MvxSpinner 中的整数列表,当我尝试使用时

      local:MvxBind="Text Caption"
      

      在 item_spinner.axml 和 item_spinnerdropdown.axml 中

      结果是一个空格,而不是我的值。我认为这是因为 int 没有 Caption 属性,所以我尝试更改绑定,使其绑定到对象本身,而不是绑定到它的属性。它是这样做的:

      local:MvxBind="Text ." 
      

      左右:

      local:MvxBind="Text"
      

      有一个关于差异的话题: Are "{Binding Path=.}" and "{Binding}" really equal

      因此,将模板代码更改为:

      item_spinner:

      <TextView xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:local="http://schemas.android.com/apk/res-auto"
          android:singleLine="true"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textColor="@color/black"
          android:text="Test"
          local:MvxBind="Text ." />
      

      Item_SpinnerDropDown:

      <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:layout_width="match_parent"
          android:layout_height="match_parent"
          local:MvxBind="Text ." />
      

      【讨论】:

        猜你喜欢
        • 2012-04-06
        • 2012-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-16
        • 1970-01-01
        • 1970-01-01
        • 2021-02-20
        相关资源
        最近更新 更多