Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3622886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:18:54+00:00 2026-05-18T23:18:54+00:00

Is there something simple i might be missing? The kruis picture shows up on

  • 0

Is there something simple i might be missing? The “kruis” picture shows up on my ImageButton, so i’m pretty sure my main.xml is good, but when i click on the ImageButton, i get no Toast and testView does not change… been struggling for a few hours on this now, not sure what i’m doing wrong!

package com.matchit;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class matchit extends Activity {

OnClickListener cardListener;
TextView testView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    testView = (TextView)findViewById(R.id.test);

    ImageButton b1 = (ImageButton)findViewById(R.id.card1);

    b1.setImageResource(R.drawable.kruis);
    b1.setOnClickListener(cardListener);

    cardListener = new OnClickListener(){

        @Override
        public void onClick(View v) {

            testView.setText("its working");
            Toast.makeText(getApplicationContext(),
                    "its working",
                     Toast.LENGTH_LONG).show();
        }
    };
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:18:54+00:00Added an answer on May 18, 2026 at 11:18 pm

    Value of cardListener is null at this line:

      b1.setOnClickListener(cardListener);
    

    Just move this line after cardListener = new OnClickListener(){

    cardListener = new OnClickListener(){
    
        @Override
        public void onClick(View v) {
    
            testView.setText("its working");
            Toast.makeText(getApplicationContext(),
                    "its working",
                     Toast.LENGTH_LONG).show();
        }
    };
    
    // moved down
    b1.setOnClickListener(cardListener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought what I wanted would be pretty simple, but there must be something
I'm afraid I'm missing something simple here, but I'm trying to put multiple buttons
I might be missing something simple, so bear with me. I have a ViewModel
There might be a stupid simple answer to this, but I'm trying to use
I think I'm missing something simple, but I'm just not seeing it. I have
I'm not a web guy, so this might be something really simple I'm missing,
Maybe I am missing something simple here, but it is frustrating me. So what
Is there a simple way in Ruby to get a true/false value from something
Is there a simple way to see assigned shortcuts with given prefix? Something similar
Is there something like die in JavaScript? I've tried with break, but doesn't work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.