android实现数据快速与组件交互

做android开发的,想必痛恨findViewById很久了吧,为了解决这茬,无数框架涌现,有android-query-full、xUtils……无非利用反射、注解之类,通过ResourceId查找view,单从数据交互方面来说,这些不能满足我的需求,因为它们都需要手动为一个个view赋值/取值。

于是,我自己写了一个quick-form,可以给一个activity上所有的组件一次性赋值,不需要手动查找单个组件。我使用这个框架已有些日子,从中受益无数,最近很闲,决定分享给大家。

源码下载:https://github.com/Ice-Drinker/quick-form


使用方法:

首先,我们在activity里创建一组数据

ContentValues values = new ContentValues();
	values.put("username", "tomcat");
	values.put("sex", "man");

然后,在layout文件中

<com.ice.ui.MEditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:tag="username" />

<com.ice.ui.MRadioGroup
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:checkedButton="@+id/no_radio_button"
	android:orientation="horizontal"
	android:tag="sex" >

	<RadioButton
		android:id="@id/no_radio_button"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:tag="women"
		android:text="women" />

	<RadioButton
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginLeft="10dp"
		android:tag="man"
		android:text="man" />
</com.ice.ui.MRadioGroup>


主要是为tag属性赋值,这个值与values里的键一致。


最后,在activity里赋值

IceTool.get().setMViewValues(getWindow().getDecorView(), values);

如图,大功告成。



自定义组件MEditText、MRadioGroup在源代码中有,源代码有完整例子。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值