Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!