Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda