Android的数据绑定(类似WPF)? [英] Android data-binding (similar to WPF)?

查看:155
本文介绍了Android的数据绑定(类似WPF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找,然后再发布一些类似的问题 - 不过,我有一个普遍的问题,当谈到Android和数据绑定(和其他的答案我检查并没有真正得到我更远...)。假设你有一个类车辆:

I have searched for some similar questions before posting - however I have a general question when it comes to Android and data binding (and the other answers I check did not really get me much further...). Assume you have a class Vehicle:

public class Vehicle {

private Owner owner;
private String brand;

//getter and setter for above attributes...

}

和这里的所有人类别....

and here is the Owner class ....

public class Owner {

private String name;

}

现在 - 我刚刚寻找到MVVM(模型视图,视图模型)模式作为受雇于微软的WPF。这让我想:假设我会想我的所有者对象的名称属性,它是车辆对象的​​子绑定 - 将出现在Android的一些标准的方式来实现这一目标?另外presuming,那我可能要验证输入之前,我可以有更新的型号?

Now - I was just recently looking into MVVM (ModelView-ViewModel) pattern as employed by Microsofts WPF. Which got me wondering: Assuming I would want to bind the name property of my owner object which is a child of the Vehicle object - would there be some standard way in Android to achieve this? Also presuming, that I might have to validate input before I can have the Model updated?

我想象以下几部分组成(假定MVVM):

I was imagining the following components (assuming MVVM):

  • 视图(的活动),不包含应用程序逻辑 - 所以它或多或少空
  • 在一个视图模型将处理的车对象的实例,并在其上​​执行操作
  • 在模型本身看起来为code我帐前 - 完全无视查看 和视图模型
  • The View (an Activity) contains no application logic - so its more or less empty
  • A ViewModel would handle the instance of the Vehicle object and perform actions on it
  • The Model itself would look as the code I posted before - totally oblivious to the View and the ViewModel

现在,当我加我EditTexts,TextViews等方面的看法,我希望他们能够绑定到特定的我的上下文对象(车辆在这种情况下)的属性... Mhhh如果我的问题不明确,或者您需要进一步informatio不要让我知道:)在此先感谢。

Now when I add my EditTexts, TextViews and so on to the view, I want them to bind to certain the properties of my context object (Vehicle in this case) ... Mhhh if my question is not clear or you need further informatio do let me know :) thanks in advance.

P.S。我认为人们熟悉的WPF可能现在我是什么意思?我自己刚刚看了一下WPF,发现这是一个不错的方式来处理的东西。

P.s. I think people familiar with WPF might now what I mean? I myself just read about WPF and found it's a nice way to handle stuff.

聚苯硫醚我知道href="http://$c$c.google.com/p/android-binding/">结合的android 项目

P.P.s I am aware of the android binding project but I was wondering if there is a sort of build-in approach in Android or maybe some convention someone is following :) this really is more of a binding-theory question I guess ...

推荐答案

没有什么烤到了Android SDK提供的MS WPF中相当于数据绑定功能。谷歌是提供用于运行机器人的各种装置一个较低的水平的界面。迄今为止,更高级别的应用程序框架还没有从Android开发社区出现了。 (恕我直言,这将发生一个巨大的公司像谷歌创造这样的事情,因为在所有的各种Android设备的框架所有不同的约束条件。)

There is nothing "baked" into the Android SDK which provides equivalent databinding functionality found in MS WPF. Google is providing a lower level interface for the various devices running Android. To date, higher level application frameworks have not emerged from the Android development community. (IMHO, it would take a monster company like Google to create such a thing, given all the different constraints on a framework for all the various Android devices.)

您可以在自己的应用程序来处理您的MVVM模式需要创建一组数据绑定类。而Databinders将设置在Android视图对象相关的事件处理程序和您的视图模型对象响应运行一些适当的方法。他们也将转化变化事件(定义)在视图模型插入视图对象的相应属性分配。

You could create a set of databinding classes in your own application to handle your needs for the MVVM pattern. The "Databinders" would set the relevant event handlers on Android View objects and run some appropriate method on your ViewModel objects in response. They would also translate change events (that you define) on the ViewModel into the appropriate property assignments on the View objects.

这是否原来是值得您的应用程序是一个主观判断。我的猜测是,它需要更多的精力来编写使用DataBinder类的不仅仅是直接挂钩较低级别视图的事件处理程序。框架是有用的,主要当你不必自己写。

Whether that turns out to be worthwhile for your application is a judgment call. My guess is that it would require more effort to write the Databinder classes than just to hook the lower level View event handlers directly. Frameworks are useful primarily when you didn't have to write them yourself.

这篇关于Android的数据绑定(类似WPF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆