Android DataBinding - Callback Listener

less than 1 minute read

ChangedCallback Listener

  • ObservableField

      observableField.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
          override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
                  ...
          }
      })
    
  • ObservableArrayList

      observableArrayList.addOnListChangedCallback(object :
          ObservableList.OnListChangedCallback<ObservableList<String>>() {
          override fun onChanged(sender: ObservableList<String>?) {
              ...
          }
    
          override fun onItemRangeRemoved(sender: ObservableList<String>?, positionStart: Int, itemCount: Int) {
              ...
          }
    
          override fun onItemRangeMoved(
                  sender: ObservableList<String>?,
                  fromPosition: Int,
                  toPosition: Int,
                  itemCount: Int
          ) {
              ...
          }
    
          override fun onItemRangeInserted(sender: ObservableList<String>?, positionStart: Int, itemCount: Int) {
              ...
          }
    
          override fun onItemRangeChanged(sender: ObservableList<String>?, positionStart: Int, itemCount: Int) {
              ...
          }
      })
    
  • ObservableArrayMap

      observableArrayMap.addOnMapChangedCallback(object :
              ObservableMap.OnMapChangedCallback<ObservableMap<String, Boolean>, String, Boolean>() {
              override fun onMapChanged(sender: ObservableMap<String, Boolean>?, key: String?) {
                  ...
              }
          })
      }
    
  • Callback Listener Github Example

Categories:

Updated:

Leave a comment