Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
I want to make this boolean value true when I click this button. And pass it to a function to display something on screen

This is the code for the button

class NewGame : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_new_game)
    val results = findViewById<TextView>(R.id.textView5)
    val results2 = findViewById<TextView>(R.id.textView6)
    val submit = findViewById<Button>(R.id.button7)
    var hasclicked = false



    submit.setOnClickListener {
        hasclicked = true

    }
    game (result, hasclicked)

This is the code for the function

fun game(
     result: TextView, hasclicked : Boolean ) {
  



    if (hasclicked == true){
        result.setText("correct")
    }

    

But when I run this and click on the button nothing appears on screen. Can someone help me with this.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

We get this error when we just set a value but do not try using it.

Here if you see your code, you are setting the value. But, not getting it.

By accessed it means that you are not getting it. Only setting it.

You can just choose to ignore it in some cases where it actually make sense,

enter image description here

What you can do is hover the affected area and press Alt + Enter in "Windows" or alt/option/⌥ + Enter in "Mac", and chose to suppress it.

You'll see,

enter image description here

over 4 years ago · Santiago Trujillo Denunciar

0

On clicking, you are only assigning true to boolean but not calling the game(result, hasclicked) function:

It should be like this:

submit.setOnClickListener {
    hasclicked = true
    game(result, hasclicked)
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda