https://kotlinlang.org logo
#android
Title
# android
g

gildor

08/30/2017, 2:43 AM
@ankitdroiddeveloper Particulary for your view it would be look like:
Copy code
class FreeView @JvmOverloads constructor(
  context: Context, 
  attrs: AttributeSet? = null,  
  defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
    init {
       // Your code to init view
    }
}
👍 4
k

kevinmost

08/30/2017, 12:45 PM
One thing we talked about in another thread where I suggested this exact same thing is that it's actually dangerous to do this.
defStyleAttr
isn't always defaulted to 0. Some classes like
EditText
require a different 3rd param. Doing this leads to very subtle bugs