使用本库后,你可以这样为EditText添加监听文本变化的接口:
EditText(this).withTextChangedListener {
ifTextChanged { s, start, before, count ->
//do sth
}
}
或者这样
EditText(this).withTextChangedListener {
ifBeforeTextChanged { s, start, count, after ->
//do sth
}
ifTextChanged { s, start, before, count ->
//do sth
}
}
或者这样
EditText(this).withTextChangedListener {
ifTextChanged { s, start, before, count ->
//do sth
}
ifAfterTextChanged {
//do sth
}
}
或者如果项目中用到了Rxjava,可以这样用Observer:
Observable.just("1", "2", "3")
.withSubscribe {
ifNext {
//do sth
}
}
或者这样
Observable.just("1","2","3")
.withSubscribe {
ifNext {
//do sth
}
ifError {
//do sth
}
}
或者这样
Observable.just("1","2","3")
.withSubscribe {
ifNext {
//do sth
}
ifComplete {
//do sth
}
}
在kotlin中用过rxjava的应该知道,subscribe时虽然官方给了些lamada表达式快捷使用,但顺序和随机使用方法确实个令人困扰的问题,故有本方案。
- TextWatcher
- ViewPager.OnPageChangeListener
- Animator.AnimatorListener
- AbsListView.OnScrollListener
- RecyclerView.OnScrollListener
- SeekBar.OnSeekBarChangeListener
- View.OnAttachStateChangeListener
- DrawerLayout.DrawerListener
- View.OnClickListener(filter)
- Observer (rx)
- FlowableSubscriber (rx)
- 一些彩蛋(๑◡๑)
repositories {
jcenter()
}
dependencies {
implementation "com.cysion:targetfun:1.2.0"
}
android studio 新版本默认 buildToolsVersion默认 28.0.2
本库目的既然是基于原SDK接口的优化使用,自然用法跟原接口特别相似, 最明显的差别就是所有的设置接口方法都是以 'with'开头,{}内的方法以if开头
彩蛋
Edittext的扩展函数,打开/关闭键盘
EditText(this).openKeyBoard()
EditText(this).hideKeyBoard()
过滤频繁点击
Button(this).clickWithLimit {
}
跳转Activity,1000请求码
gotoActivityForResult<EditExActivity>(1000)
gotoActivity<EditExActivity>()
str(resid), drawable(resid)等方法
TextView(this).text=str(R.string.app_name)
待补充...
Copyright 2018 CysionLiu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.