dimsuz
12/29/2016, 4:45 PMclass MyView : View {
private val textView: TextView
private val progressVisualizationView: ProgressVisualizationView
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
context.layoutInflater().inflate(R.layout.view_progress_bar, this, true)
progressVisualizationView = getChildAt(0) as ProgressVisualizationView
textView = getChildAt(1) as TextView
}
}
Intention suggests me do the following:
class MyView : View {
private val textView: TextView = getChildAt(1) as TextView
private val progressVisualizationView: ProgressVisualizationView = getChildAt(0) as ProgressVisualizationView
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
context.layoutInflater().inflate(R.layout.view_progress_bar, this, true)
}
}
but in android those getChild()
lines depend on the line above - the view must be inflated and populated with children, so I could invoke getChildAt()
on it.
Without giving it much thought I done what was suggested and app crashed 🙂