问题描述
我有一个问题铸件。
首先,我要举一个例子如何做自动完成自定义适配器没有MVVM在MonoDroid的:的
i've a problem with castings.First i will give an example how to do a custom Adapter for AutoComplete without MVVM in Monodroid: https://github.com/BitStab/Monodroid-Custom-Auto-Complete/blob/master/MonoAndroidApplication1/CustomerAdapter.cs
现在我会尝试这MVVMCross,但要做到这一点,我会通过的java.lang.Object致以视图模型。这会破坏它的便携性。我在寻找,现在要解决此问题,并导致我在MVVM不是专家,我需要帮助。
Now i will try this in MVVMCross, but to do it, i would have to extend my ViewModel by Java.Lang.Object. This would destroy the portability of it. I'm searching right now a workaround and cause i'm no expert on mvvm i need help.
我开始做一些新的类在mvvmCross Bindigs,因为你可以在这里找到:
I started to do some new classes in the mvvmCross Bindigs, as you can find it here: https://github.com/BitStab/MvvmCross/tree/master/Cirrious/Cirrious.MvvmCross.Binding/Android/Views
我试图使它作为一般的有可能,但我需要从我个人的C#对象的java.lang.Object投的方法。
有没有做到这一点的方法,并且不延长我的ViewModel?
。如果有人有另外一种想法,我很乐意得到灵感!
I'm trying to make it as generic as possible, but i need a method to cast from my personal C# object to Java.Lang.Object.Is there a method to do this without extending my ViewModel?If someone has another idea, i'd be happy to get the inspiration!
感谢您的帮助!
推荐答案
如果你想移植的代码,那么你肯定不希望有Java.anything靠近你的ViewModels的任何地方。
If you want portable code, then you certainly don't want to have Java.anything anywhere near your ViewModels.
我怕我真的无法按照CustomerAdapter示例代码 - 过滤器和发布方式看起来不完全正确。此外,我还不能跟上大多数Java示例,我发现了一些问题 - 从我所看到的,我不认为在AutoCompleteTextView线程模型是理想的 - 它可以阻止太久(恕我直言)一个线程
I'm afraid I couldn't really follow the CustomerAdapter example code - your filter and publish methods don't look quite right. Further, I had some problems following most of the Java samples I found - from what I've seen, I don't think the threading model on the AutoCompleteTextView is ideal - it blocks a thread for too long (IMHO).
然而,在谷歌图书API样本一些黑客攻击后,我创建了一个示例 - 看视频,时间:
However, after some hacking at a Google Books API sample, then I created a sample - see the video at:
- YouTube的 -
- YouTube - http://www.youtube.com/watch?v=l9JqlA_YZ4k
本例使用MvvmCross框架内的一个新的字母的数据绑定自动完成类和适配器。这可能是因为这些类实际上从未晋级成为全职框架成员 - 在这种情况下,他们可以住在,而不是一些外部库
This example works using a new alpha databinding Autocomplete class and adaptor within the MvvmCross framework. It may be that these classes never actually make the cut to be full time framework members - in which case they can live in some external library instead.
基本功能使用数据绑定3新的属性:
The basic functionality uses databinding on 3 new properties:
- PartialText - 这是部分文本字符串 - 从视图到视图模型发送
- 的ItemsSource - 这是可以设定经常项目为提供PartialText - 从视图模型送到视图
- SelectedObject - 这是当前所选的项目 - 从视图发送到视图模型
您可以在结合XML作为看看这些设置:
You can see these setup in the binding xml as:
<Mvx.MvxBindableAutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxItemTemplate="@layout/listitem_book"
local:MvxBind="{'Text':{'Path':'EnteredText','Mode':'TwoWay'},
'ItemsSource':{'Path':'AutoCompleteSuggestions'},
'PartialText':{'Path':'CurrentTextHint'},
'SelectedObject':{'Path':'CurrentBook'}}"
/>
请注意,由于Android的线程模型很重要的是在PartialText每一个变化是由最终满足。信号变化的ItemsSource - 这应该是对象集合在一个单一的改变,而不是很多小的变化
Note that because of the Android threading model it is essential that every change in PartialText is met by an eventual signalled change in ItemsSource - and this should be a single change in object collection rather than lots of small changes.
这个初始样本中的代码是:的
The code for this initial sample is in: https://github.com/slodge/MvvmCross/tree/master/Sample%20-%20SimpleDialogBinding/SimpleBinding/DroidAutoComplete
请注意,此示例使用简单绑定,而不是完整的MVX框架,因此有。略多线程担心在视图模型
Note that this sample uses "simple binding" rather than the full Mvx framework and as a result there is slightly more threading to worry about in the ViewModel.
绑定视图及其适配器都不是简单的代码来跟随 - 绑定代码在本质上是相当抽象 - 但他们可以中找到:
The binding view and its adapter are not simple code to follow - the binding code is fairly abstract in nature - but they can be found in:
- 的
- 的
- MvxBindableAutoCompleteTextView
- MvxFilteringBindableListAdapter
如果你正在做什么网络链接,然后从长远来看,我相信它可以更好地实施新的自动完成功能视图,而不是使用内置的Android今天!
If you are doing anything network-linked then in the long term I believe it may be better to implement a new autocomplete view rather than to use the built into Android today!
这篇关于自动完成MVVM和Java铸件不会对视图模型使用的java.lang.Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!