Android EditText Binding is broken after MvvmCross update from 4.2.3 to 4.4.0 with Linker enabled

你说的曾经没有我的故事 提交于 2019-12-05 00:02:52

问题


My MvvmCross Android app which was working before now is broken because of MvvmCross update from 4.2.3 to 4.4.0

<EditText
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   local:MvxBind="Text Login" />

public string Login
{
    get { return _login; }
    set { SetProperty(ref _login, value); }
}

LinkerPleaseInclude if of course there:

public void Include(EditText text)
        {
            text.Enabled = !text.Enabled;
            text.TextChanged += (sender, args) => text.Text = "" + text.Text;
            text.Hint = "" + text.Hint;
            text.Click += (s, e) => text.Visibility = text.Visibility - 1;
        }

        public void Include(TextView text)
        {
            text.TextChanged += (sender, args) => text.Text = "" + text.Text;
            text.Hint = "" + text.Hint;
            text.Click += (s, e) => text.Text = text.Text + "";
        }

Linker "SDK Only" enabled. For disabled linker it works fine. Other bindings works fine as well (button clicks, visibilities, etc).

How to tell linker to handle this properly? What could be wrong here?


回答1:


The binding target for EditText and TextView uses the AfterTextChanged event, which probably gets linked away. Add that to your Include methods instead of TextChanged and it should work:

public void Include(TextView text)
{
    text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
    text.Hint = "" + text.Hint;
    text.Click += (s, e) => text.Text = text.Text + "";
}

I don't think you need a separate method for EditText as EditText inherits from TextView.



来源:https://stackoverflow.com/questions/40432756/android-edittext-binding-is-broken-after-mvvmcross-update-from-4-2-3-to-4-4-0-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!