GithubHelp home page GithubHelp logo

smilingboy / android-forms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xuell0601/android-forms

0.0 0.0 0.0 1002 KB

Android 动态表单,支持常用表单(文本框、选择框、下拉框、弹出框、日期选择框)、表单验证、表单渲染。

License: Apache License 2.0

Kotlin 100.00%

android-forms's Introduction

Android Kotlin 表单库

基于RecyclerView 的Android 动态表单,当默认的表单项无法满足业务需求可自定义扩展。

1、功能列表

  • 单选框

  • 复选框

  • 日期选择

  • 文本框:单行文本、多行长文本、数字输入、浮点输入、手机号码、自定义输入类型等。

  • 单项列表选择框:支持多级选择,自定义数据项数据源(如字典表)。

  • 表单过滤器:支持自定义内容过滤,如:敏感字符过滤、非法日期选择过滤等等。

  • 表单关联:一个表单项关联多个子表单的情况,一般为是否xxx然后关联要填写的表单内容。

  • 表单校验:支持自定义验证器,高亮定位到错误位置。

  • 数据绑定:支持表单直接关联到实体类,实时更新实体字段值。

  • 扩展表单:基于viewType来定义表单类型,方便自行自定义表单和表单渲染。

2、布局、图标、颜色自定义

表单库均已from_xxx的规范命名。

颜色修改:修改颜色时在你的主程序的样式中覆盖colors.xml定义的颜色值即可。

图标修改:以相同的文件名直接放在你的主程序下即可。

布局修改:在本项目layout中复制一份你要修改的布局到你的主程序下做对应的修改即可。

开始使用

buildscript {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    // $TAG取JitPack最新版本
	implementation 'com.github.raedev:android-forms:Tag'
}

示例演示

更多使用示例请查看MainActivity

所有表单项

纯展示只读状态

表单校验(高亮)

多级选项

日期选择

自定义表单

大概步骤如下,或者参考EditTextFormItem 来实现。

  1. EditTextFormItem2 继承 EditTextFormItem
  2. 重写以下方法
  override val layoutId: Int = R.layout.form_item_edit_text2
  // 类型自己定义,不要跟FormType重复即可
  override val formType: Int = 123123
  // 实现自己的方法
  override fun onBindViewHolder(holder: FormViewHolder){}
  override fun onBindViewEvent(holder: FormViewHolder){}
  override fun onUnBindViewEvent(holder: FormViewHolder){}

3、重写一个FormRender表单渲染器

class YourFormRender(
    context: Context,
    adapter: FormGroupAdapter,
    fragmentManager: FragmentManager
) : FormRender(context, adapter, fragmentManager) {

    /**
     * 添加文本编辑框
     */
    protected open fun addEditText2(
        inputType: FormInputType,
        label: String, name: String, value: String? = null, required: Boolean = false,
        parent: FormItem? = null,
    ): EditTextFormItem {
        return EditTextFormItem2(inputType, label, name, value, required).addToFormGroup(parent)
    }
}

android-forms's People

Contributors

raedev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.