Advertisement
Guest User

Untitled

a guest
Sep 14th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.01 KB | None | 0 0
  1. @ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
  2. class ItemView @JvmOverloads constructor(
  3.     context: Context,
  4.     attributeSet: AttributeSet? = null,
  5.     defStyleAttr: Int = 0
  6. ) : ConstraintLayout(context, attributeSet, defStyleAttr) {
  7.     init {
  8.         View.inflate(context, R.layout.layout_item_view, this)
  9.     }
  10.  
  11.     private var listener: Listener? = null
  12.  
  13.     @ModelProp
  14.     fun setItem(item: Item) {
  15.         et_item.tag = item.id
  16.         et_item.setText(item.text)
  17.         et_item.setSelection(et_item.text.length)
  18.  
  19.         et_item.addTextChangedListener(TextWatcherFactory.create {
  20.             listener?.onTextChanged(item.id, it.toString())
  21.         })
  22.     }
  23.  
  24.     @OnViewRecycled
  25.     fun clear() {
  26.         listener = null
  27.     }
  28.  
  29.     @CallbackProp
  30.     fun setTextChangeListener(listener: Listener?) {
  31.         this.listener = listener
  32.     }
  33.  
  34.     interface Listener {
  35.         fun onTextChanged(id: Int, text: String)
  36.     }
  37.  
  38.     data class Item(val id: Int, val text: String)
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement