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

  • SEARCH
  • Home
  • 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 9267009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:27:00+00:00 2026-06-18T14:27:00+00:00

In my android application I’m changing button image for 1 sec. There is group

  • 0

In my android application I’m changing button image for 1 sec. There is group of buttons. In that 1 sec image of any one button is get changed. If in that 1 sec I click on that particular button I want to perform some operation.using onclick listener i tried but it’s not working. How can I do this? Please help me below is the code-

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.next);

myTimer = new Timer();

myTimer.schedule(new TimerTask() {  

@Override
public void run() {
  if(time==-1){

    onStop();
  }
  else
    runOnUiThread(new Runnable() {
    public void run() {

      Random rand=new Random();               
      time=time-1;
      but1=(Button) findViewById(R.id.b1);
      but1.setBackgroundResource(R.drawable.happy);
      but1.setContentDescription("happy");
      but2=(Button) findViewById(R.id.b2);
      but2.setBackgroundResource(R.drawable.happy);
      but2.setContentDescription("happy");

      int num = rand.nextInt(buttonIds.length);
      int buttonId = buttonIds[num];

      Button bb=(Button) findViewById(buttonId);

      if(bb.getContentDescription().equals(button.getContentDescription()))
      {
        bb.setBackgroundResource(R.drawable.happy);
        bb.setContentDescription("happy");
        wrong++;
      }
      else
      {
        bb.setBackgroundResource(R.drawable.whoa);
        count++;

        bb.setContentDescription("whoa");
      }

    }
  });
}

},0, 1000);
}

public void onClick(View v){
//when i clicked on any button its not even entering here
System.out.println("in onlcik............");
int aaa=v.getId();
System.out.println("click id is------------"+aaa);
for(i=0;i<9;i++){
if(aaa==buttonIds[i]){
    findViewById(buttonIds[i]).setOnClickListener(new View.OnClickListener() {

        Drawable dd=findViewById(buttonIds[i]).getBackground();
        public void onClick(View arg0) {
         System.out.println("yes...");

        }
    });
}
}
}

 }
  • 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-06-18T14:27:01+00:00Added an answer on June 18, 2026 at 2:27 pm

    It looks like you forgot to add onClickListener to your buttons.

    Try adding

     but1.setOnClickListener(this);
        but2.setOnClickListener(this);
    

    to your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My android application possesses two fragments 1. Left one( that is a menu list)
my android application is formed by several activity, one service (that communicate with a
My android application needs frequent access to sqlite database. I was thinking if there
My android application starts a service in the onCreate() callback of a class that
I have an Android application that targets API 17 and has a minimum SDK
my Android application needs to play .swf files, which are sound only.. Is there
I have a C++ Android application that I'm trying to debug with ndk-gdb. The
My Android application uses minSdkVersion=3 and targetSdkVersion=8. I used 8 because that is the
My Android application has an ActionBar that changes which Fragment occupies a certain FrameLayout
My Android application does some calculations, but I noticed recently that if I were

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.