Skip to content

Instantly share code, notes, and snippets.

@dafma
Created May 27, 2017 19:38
Show Gist options
  • Save dafma/ced096e65fcffd423d4a58732209d28b to your computer and use it in GitHub Desktop.
Save dafma/ced096e65fcffd423d4a58732209d28b to your computer and use it in GitHub Desktop.
cambiar el texto de un diccionario en android
/*Definir primero textview y button en el xml*/
package com.example.mrk2.platzykotlin
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
data class Cursos(val nombre:String, val url:String)
class MainActivity : AppCompatActivity() {
val react = Cursos("React", "react")
val kot = Cursos("Kotlin", "kotlin")
var cursoActual = react.copy()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val boton = findViewById(R.id.botoncito) as Button
boton.setOnClickListener{
view -> switchCurso(cursoActual)
}
boton.setText(todosLosCursos())
}
fun switchCurso(curso:Cursos)
{
cursoActual = curso.copy()
when(curso.url)
{
"react" -> cursoActual= kot.copy()
"kotlin" -> cursoActual= react.copy()
else -> print("çesto nunca va a pasar")
}
verEnPantalla("Curso de ${cursoActual.nombre} en platzy.com/${cursoActual.url} ")
}
fun verEnPantalla(s:String)
{
val txt = findViewById(R.id.texto) as TextView
txt.setText(s)
}
fun todosLosCursos(): String = "${react.nombre} y ${kot.nombre}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment