mvvm
来源:互联网 发布:网络代刷平台 编辑:程序博客网 时间:2024/05/02 00:55
mvc
v layout 就是view
c activity 是控制层
1个业务相关
2界面相关
布局的加载 布局的 初始化都在activity中
就导致activity比较代码臃肿
mvp
将acitivity中的业务部分的拆分出来就是 mvp
写一个类p 去处理业务逻辑
mvvm这个框架就是15谷歌推出的
android 下面的
1 先在当前应用的grdle里面进行配置信息
android 下面括号包裹着
进入DataBing的框架
2 在布局文件中把bean的类与textView 组件关联起来
就没有settext findbyid
3 给组件设值
import android.content.Context;import android.content.Intent;import android.databinding.DataBindingUtil;import android.os.Bundle;import android.os.PersistableBundle;import android.support.v7.app.AppCompatActivity;import android.util.AttributeSet;import android.view.View;import com.example.mymvvp.bean.User;import com.example.mymvvp.databinding.ActivityMainBinding;import com.example.mymvvp.userevent.UserEvent;/** * 在添加EditText内容事件的event和bean 好像是不能同时存在 */public class MainActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startActivity(new Intent(this,EditTextActivity.class));/* User user = new User(); user.age = "18ww"; user.name = "dada"; UserEvent uv=new UserEvent(user); ActivityMainBinding binding; binding = DataBindingUtil.setContentView(this, R.layout.activity_main);// binding.setUser(user);// binding.setEvent();*/ } @Override public View onCreateView(String name, Context context, AttributeSet attrs) { return super.onCreateView(name, context, attrs); }}
import android.databinding.DataBindingUtil;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import com.example.mymvvp.bean.User;import com.example.mymvvp.databinding.ActivityMainBinding;import com.example.mymvvp.userevent.UserEvent;public class EditTextActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);// setContentView(R.layout.activity_edit_text); ActivityMainBinding binding= DataBindingUtil.setContentView(this,R.layout.activity_edit_text); User user=new User(); UserEvent userEvent = new UserEvent(user); binding.setEvent(userEvent); } public void onorgin(View view) { }}
<?xml version="1.0" encoding="utf-8"?><layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="event" type="com.example.mymvvp.userevent.UserEvent"/> </data> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/ll" > <EditText android:id="@+id/et_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入姓名" android:addTextChangedListener="@{event.user_name}" /> <EditText android:id="@+id/et_age" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入年龄" android:addTextChangedListener="@{event.user_age}" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onorgin" android:text="注册"/> </LinearLayout></layout>
0 1
- MVVM
- MVVM
- MVVM
- MVVM
- MVVM
- MVVM
- MVVM
- MVVM
- mvvm
- MVVM
- MVVM
- mvvm
- MVVM
- MVVM
- MVVM
- MVVM
- MVVM
- MVVM
- 李航统计学习方法-改进的迭代尺度算法(IIS)总结
- java 输入一个链表,输出该链表中倒数第k个结点。
- poj 3280 Cheapest Palindrome(区间dp)
- git如何与原始仓库同步
- 【Python学习日记】字符编码
- mvvm
- 《LDA漫游指南》数学基础阅读笔记
- 表情识别数据集整理
- hibernate延迟加载分析
- OC基础:Block简介
- jQuery选择器
- JAVA面试中问及HIBERNATE与 MYBATIS的对比,在这里做一下总结
- 【洛谷1025 数的划分】【搜索】
- android binder