Android的数据绑定(类似WPF)?绑定、类似、数据、Android

2023-09-03 21:16:14 作者:枪杀我@

我已经寻找,然后再发布一些类似的问题 - 不过,我有一个普遍的问题,当谈到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 项目