Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducción a Kotlin para Android Developers

Introducción a Kotlin para Android Developers

Una charla introductoria sobre Kotlin para Desarrolladores Android dada en la Kotlin Meetup #01 de Lima Kotlin

Avatar for Armando Picón

Armando Picón

March 25, 2017
Tweet

More Decks by Armando Picón

Other Decks in Programming

Transcript

  1. Lima Kotlin User Group aka. “Lima Kotlin” Nuestras redes sociales:

    Twitter @LimaKotlin Facebook: https://www.facebook.com/groups/limakotlin/
  2. public class Person{ private String name; private int age; public

    Person(String name, String age){ this.name = name; this.age = age; } public String getName(){ return this.name; } public int getAge(){ return this.age; } } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  3. class Persona constructor(name:String, age: Int){ val name = name var

    age = age } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  4. // Clase simplificada class Persona(val name: String, var age: Int)

    Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  5. // Data class data class Persona(val name: String, var age:

    Int) Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  6. List people = new ArrayList<Person>(); people.add(new Person(“Armando”,35)); people.add(new Person(“Erik”,26)); people.add(new

    Person(“Adrian”,30)); forEach(Person person: people){ if(person.getName().equals(“Erik”)){ return person; } } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  7. val people = listOf<Person>( Person("Adrian", 30), Person("Erik",26), Person("Armando", 35)) val

    person = people.find { it.name == "Erik" } println(person) Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  8. val numberList = listOf(1, 2, 3, 4, 5) val squared

    = list.map( i -> i * i) assertTrue(squared.containsAll(listOf(1,4,9,16,25))) squared.forEach { println(it) } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  9. public class MyActivity extends AppCompatActivity{ @Override public void onCreate(Bundle saveInstanceState){

    super.onCreate(saveInstanceState); setContentView(R.layout.main_activity); TextView myTextView = (TextView) findViewById(R.id.my_textview); myTextView.setText(“¡Hola Android!”); } } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  10. class MyActivity : AppCompatActivity{ override fun onCreate(saveInstanceState:Bundle){ super.onCreate(saveInstanceState); setContentView(R.layout.main_activity); val

    myTextView = findViewById(R.id.my_textview) as TextView; myTextView.text = “¡Hola kotlin!” } } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  11. fun ImageView.loadImage(url: String?){ if(url != null){ Glide.with(this.context) .load(url) .fitCenter() .into(this)

    } } myImageView.loadImage(“!insert an url here!”) Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14
  12. var message : String? = null fun sayHello(message:String?){ if(message !=

    null){ println(message) } } Gist: https://gist.github.com/DevPicon/58911d67b05d25106ca3d7699934ce14