<?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. npm 使用代理

    npm install 有时候会安装失败,可能是网络的问题,可以使用代理来安装 npm获取配置有6种方式,优先级由高到底. 命令行参数. --proxy http://server:port即将pro ...

  2. hdu 3440 House Man

    差分约束系统 例如, 5 6  20 34 54 10 15  这一组测试数据 先编号,分别为1 2 3 4 5 ,然后可以写出一组表达式,两个编号之间的距离必定大于等于1的,所以i+1到i建立有向边 ...

  3. jquery 固定导航

    网页代码: <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> & ...

  4. [转]详细的mysql时间和日期函数

    这里是一个使用日期函数的例子.下面的查询选择了所有记录,其date_col的值是在最后30天以内: mysql> SELECT something FROM table WHERE TO_DAY ...

  5. 关于php的socket

    这里仅记录tcp协议: 关于server: <?php /** * 测试关于php的socket函数 */ /** * 最基本的socket,服务器端: * 创建 * $sock = socke ...

  6. ASP.NET MVC 实现AJAX跨域请求的两种方法

    通常发送AJAX请求都是在本域内完成的,也就是向本域内的某个URL发送请求,完成部分页面的刷新.但有的时候需要向其它域发送AJAX请求,完成数据的加载,例如Google. 在ASP.NET MVC 框 ...

  7. Excel教程(12) - 数学和三角函数

    ABS     用途:返回某一参数的绝对值.   语法:ABS(number) 参数:number 是需要计算其绝对值的一个实数. 实例:如果 A1=-16,则公式"=ABS(A1)&quo ...

  8. The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

    消息筛选器显示应用程序正在使用中. ((错误来自 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) 在对Word文档进行合并或者其他操作的时候,如果数 ...

  9. 团队项目(spring会议)

    [例会时间]2014/4/11 [例会地点]一教213课堂上 [例会形式]小组讨论 [例会主持]马翔 [例会记录]兰梦 在这次会议上,我们针对我们的项目进行了分割,并分别认领各自的任务 下面是任务的认 ...

  10. NOIP2014-普及组复赛-第一题-珠心算测验

    题目描述 Description 珠心算是一种通过在脑中模拟算盘变化来完成快速运算的一种计算技术.珠心算训练,既能够开发智力,又能够为日常生活带来很多便利,因而在很多学校得到普及. 某学校的珠心算老师 ...