<?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. SSL单向认证和双向认证原理

    注:本文为个人学习摘录,原文地址:http://edison0663.iteye.com/blog/996526 为了便于更好的认识和理解 SSL 协议,这里着重介绍 SSL 协议的握手协议.SSL ...

  2. PHP中使用CURL(六)

    curl常用的几个例子 1.抓取无访问控制文件 <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://local ...

  3. spring容器启动的加载过程(一)

    使用spring,我们在web.xml都会配置ContextLoaderListener <listener> <listener-class> org.springframe ...

  4. [FBA]SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用

    //http://tech.ddvip.com/2014-05/1401197453210723.html 由于项目的需要,登录SharePoint Application的用户将从一个统一平台中获取 ...

  5. VMware 下的Linux系统远程连接putty

    ifconfig查看ip地址 虚拟网卡需要自己新建  nat8 putty不能显示中文的解决办法 http://jingyan.baidu.com/article/5552ef47df8a97518f ...

  6. ural 1073.Square Country(动态规划)

    1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...

  7. javascript显式类型的转换

    显式类型转换目的:为了使代码变得清晰易读,而做显示类型的转换常使用的函数:Boolean(),String(),Number()或Object()如:Nunber(5) //5String(true) ...

  8. __doPostBack初识

    周五在公司看到有看到Request.Params["__EVENTARGUMENT"]的代码不解,不解遂上网查找,发现一篇文章<Understanding the JavaS ...

  9. oracle导入导出数据库

    oracle导出dmp文件: 开始->运行->输入cmd->输入 exp user/password@IP地址:1521/数据库实例 file=文件所在目录 (如:exp user/ ...

  10. Struts2--课程笔记3

    获取ServletAPI: 第一种方式: //在request域中放入属性req,暂且认为getContext()获取的是request域空间,但实际不是        ActionContext.g ...