Attention: Please consider switching to view binding in the coming months.
ButterKnife-esque view binding for Kotlin based on KotterKnife.
public class PersonView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs){
val firstName: TextView by bindView(R.id.tv_first_name)
val lastName by bindView<TextView>(R.id.tv_last_name)
// Optional binding
val middleName: TextView? by bindOptionalView(R.id.tv_middle_name)
// List binding
val nameViews: List<TextView> by bindViews(R.id.tv_first_name, R.id.tv_last_name)
// List binding with optional items being omitted
val nameViews: List<TextView> by bindOptionalViews(R.id.tv_first_name, R.id.tv_middle_name, R.id.tv_last_name)
}
These methods are available on subclasses of View
, Activity
, Dialog
, DialogFragment
, Fragment
and RecyclerView's ViewHolder
.
implementation 'be.mickverm.viewbinding:viewbinding:1.0.2'
Copyright 2020 Michiel Vermeersch
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.