반응형
val tradeConditionObservable = Observable.create<CharSequence>{emitter ->
etTradeConditionContents.addTextChangedListener(object: TextWatcher {
var str = ""
override fun afterTextChanged(s: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(s: CharSequence?, p1: Int, p2: Int, p3: Int) {
s?.let {
emitter.onNext(it)
}
}
})
}
tradeConditionObservable
.debounce(500L, TimeUnit.MILLISECONDS)
.filter{ !it.isNullOrEmpty()}
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
val length = it.toString().toByteArray(Charset.forName("UTF-8")).size
tvTradeConditionCount.text = String.format(R.string.orderregist_tradecount_contents.toResString(), length)
if (length > 300) {
etTradeConditionContents.setText(strTradeCondition)
etTradeConditionContents.setSelection(strTradeCondition.length)
tvTradeConditionCount.text = String.format(R.string.orderregist_tradecount_contents.toResString(), strTradeCondition.toByteArray(Charset.forName("UTF-8")).size)
}
else{
strTradeCondition = it.toString()
}
}
반응형
'안드로이드 > Android View' 카테고리의 다른 글
리싸이클러뷰 기초 (0) | 2022.11.04 |
---|---|
[Android] DrawerLayout 숨겨있다가 액션 취하면 나타나는 기능 (0) | 2022.11.04 |
[Android] Coordinatorlayout에 대해 알아보자 (0) | 2022.11.04 |
[Android] Elevation (그림자 효과) (0) | 2022.10.27 |
Android 뷰페이저2 (0) | 2022.04.16 |