The difference between java and kotlin in android studio - Joklinz-Tech

Latest

Home Of Tech news,jobs and android tutorials

Thursday, 14 December 2017

The difference between java and kotlin in android studio


Java makes your line of code very long while kotlin makes it short and simple
 see below how to add a click event a button using java and kotlin

Java button click event

Button btn1 = (Button)findViewById(R.id.button1);

btn1.setOnClickListener(new View.OnClickListener() {            
    @Override
    public void onClick(View v) {
//your stuff here.
    }
});

Kotlin button click event

Val btn1 = findViewById<View>(R.id.button1) as Button

btn1.setOnClickListener {            
    
//your stuff here.
    }

No comments:

Post a Comment