专栏名称: Carson_Ho
1. 简书认证作者、CSDN签约作者、稀土掘金专栏作者 2. 专注分享 Android开发干货 3. 博客地址 Github: https://github.com/Carson-Ho CSDN: http://blog.csdn.net/carson_ho 稀土掘金: https://juejin.im/user/58d4d9781b69e6006ba65edc
目录
相关文章推荐
51好读  ›  专栏  ›  Carson_Ho

Android RxJava 实际应用讲解:联合判断多个事件

Carson_Ho  · 简书  · android  · 2017-11-06 08:42

正文

请到「今天看啥」查看全文


示意图

目录

示意图

1. 需求场景

需要同时对多个事件进行联合判断

如,填写表单时,需要表单里所有信息(姓名、年龄、职业等)都被填写后,才允许点击 "提交" 按钮


2. 功能说明

  • 此处采用 填写表单 作为联合判断功能展示
  • 即, 表单里所有信息(姓名、年龄、职业等)都被填写后,才允许点击 "提交" 按钮

3. 具体实现

  • 原理
    采用 RxJava 组合操作符中的 combineLatest() 实现

关于组合操作符中的 combineLatest() 的使用请看文章:: Android RxJava:组合 / 合并操作符 详细教程

  • 具体代码实现

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="请填写姓名"
        />

    <EditText
        android:id="@+id/age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="请填写年龄"
        />

    <EditText
        android:id="@+id/job"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="请填写职业"
        />

    <Button
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"
        android:enabled="false"
        />


</LinearLayout>

MainActivity.java







请到「今天看啥」查看全文