<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.cunli.databing.web.User"/> </data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@={user.email}"
android:id="@+id/email"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@={user.password}"
android:id="@+id/password"
android:layout_marginTop="10dp"/> <Button
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:onClick="hello"
android:text="@string/app_name"/> </LinearLayout>
</layout> package com.example.cunli.databing.web; import android.databinding.BaseObservable;
import android.databinding.Bindable; import com.example.cunli.databing.BR; /**
* Created by winder on 2016/7/6.
*/
public class User extends BaseObservable {
public String email;
public String password; public User() {
} public User(String email, String password) {
this.email = email;
this.password = password;
} @Bindable
public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
notifyPropertyChanged(BR.password);
} @Bindable
public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
notifyPropertyChanged(BR.email);
} } package com.example.cunli.databing.activity; import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast; import com.example.cunli.databing.R;
import com.example.cunli.databing.databinding.ActivityMainBinding;
import com.example.cunli.databing.server.TeachLogServer;
import com.example.cunli.databing.web.CheckTeachLog;
import com.example.cunli.databing.web.TeachLog;
import com.example.cunli.databing.web.User; public class MainActivity extends AppCompatActivity { private TeachLogServer teachLogServer = new TeachLogServer();
User user; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); user = new User("haliluya", "thankyoulord");
binding.setUser(user); } public void hello(View view){ Log.e("password","------getEmail------- "+user.getEmail()); Toast.makeText(this,user.getEmail()+"\t"+user.getPassword(), Toast.LENGTH_SHORT).show();
} }

DataBinding的更多相关文章

  1. android黑科技——完美解决界面逻辑的数据框架DataBinding(最新)的使用(二)

    昨天我们一起学习了dataBinding的基础用法,我想你可能还停留在它只是不用再findViewById,其实不然,今天我们就来扩展延伸,看看这个框架到底有什么魔力让谷歌官方大力推崇.这里还没看昨天 ...

  2. Debug Databinding Issues in WPF

    DataBinding is one of the most powerful features in WPF. But because it resolves the bindings at run ...

  3. Google官方关于Android架构中MVP模式的示例续-DataBinding

    基于前面的TODO示例,使用Data Binding库来显示数据并绑定UI元素的响应动作. 这个示例并未严格遵循 Model-View-ViewModel 或 Model-View-Presenter ...

  4. jface databinding:部分实现POJO对象的监测

    在前一篇博文<jface databinding/PojoBindable实现对POJO对象的支持  >中,已经知道直接对POJO对象进行修改,是不能被绑定的UI组件知道的,在上一篇文章中 ...

  5. DataBinding examples

    Databinding in Windows Forms demo (CSWinFormDataBinding) /************************************* Modu ...

  6. 【转】Native JavaScript Data-Binding

    原文转自:http://www.sellarafaeli.com/blog/native_javascript_data_binding Two-way data-binding is such an ...

  7. 配置Kotlin环境(DataBinding)

    1.安装Kotlin插件 在plugin中搜索kotlin,安装两个kotlin插件,重新启动Android Studio.2.build.gradle(project level) buildscr ...

  8. Android官方数据绑定框架DataBinding

    数据绑定框架给我们带来了更大的方便性,以前我们可能需要在Activity里写很多的findViewById,烦人的代码也增加了我们代码的耦合性,现在我们马上就可以抛弃那么多的findViewById. ...

  9. AngularJS学习--- AngularJS中数据双向绑定(two-way data-binding) orderBy step4

    1.切换工作目录 git checkout step- #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-mo ...

  10. 复杂的databinding接受Ilist作为数据源

    Combobox控件绑定数据源时,List<T>可以作为数据源,但是List<String,Object> 不存在,我们有时候需要用Dictionary<String,o ...

随机推荐

  1. apache增加php版本

    把新的php版本解压到与旧的php版本相同目录 在新的php文件夹根目录复制一个 php.ini-development 重命名为 php.ini打开php.ini, 搜索 extension_dir ...

  2. 在Pythonanywhere上部署Django

    1 在github上创建一个仓库blog 2 克隆到本地,添加Django项目,再推送到github 3 克隆到pythonanywhere,以后每次更新用git pull即可 4 在pythonan ...

  3. iis虚拟目录或应用程序不继承父站点的web.config配置信息

    A为主站点 B为A的应用程序站点 再A的web.config中对不想继承的节点用location 套起来.如下: <location path="." allowOverri ...

  4. MySQL5.5.28启动错误 The server quit without updating PID file

    今天重新安装了一次 MySQL5.5.28 ,但启动的时候老是报错 Starting MySQL.. ERROR! The server quit without updating PID file ...

  5. C#.NET的微信功能开发学习

    对于新手的我来说,我不是申请一个微信公众号认证后进行开发,我是申请一个订阅号,然后通过自己申请的订阅号的公众平台测试号来学习. 一,申请后成功后,打开开发者工具-公众平台测试号 二,进去公众平台测试号 ...

  6. Save Update saveOrUpdate delete

    参考:Hibernate Session的saveOrUpdate()方法 saveOrUpdate与Update的作用 Hibernate Delete query Hibernate Basics ...

  7. C# delegate的匿名方法

  8. post请求和get请求

    get请求在链接后面带参数,容易出现乱码,是坑(慎用),有固定的长度 一般的用的就是post方式 <form action="<%=basePath%>upload&quo ...

  9. .Net使用JsonSchema验证Json

    最近项目中遇到了这样的需求,需要对上传的Json进行验证,以确保Json数据的准确性.前后使用了两种方式来验证: (1)第一种方式的实现思想:根据Json数据的格式,严格定义相应的类结构,并在Syst ...

  10. 正方形网格 TRIANGLE_STRIP连接

    unsigned int vIdx = 0, iIdx = 0; for (unsigned int stripRow = 0; stripRow < stripRows; stripRow++ ...