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 5941029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:03:09+00:00 2026-05-22T16:03:09+00:00

So, I am again, asking a very basic question. I apologize for my ineptness

  • 0

So, I am again, asking a very basic question. I apologize for my ineptness but I guess I read the given tutorials on these topics poorly. My question is as follows:

I would like to use a “listener” pattern to handle button presses on my GUI. I believe an onClickListener is what I need to use to handle these button presses. However, I’m not sure if I should be creating and handling events that occur after the GUI is created within an onCreate method. The following code is within my onCreate method for one of my Activities:

View.OnClickListener upDownListener = new View.OnClickListener() 
    {       
        @Override
        public void onClick(View v) 
        {


            if(v == (upOneButton))
            {
                Log.d("OptionSelect", "Up One Button Pressed.");
                ops.getOptionList().get(0).incrementProbability(4);
            } . . .

This method being called updates some GUI text with a different number. It is being called, but the GUI isn’t responding. I imagine this has to do with my attempt to use it within the onCreate method.

In short, what is a good and simple way to deal with user events within a GUI and where should this occur?

Thank you so much.

EDIT: Log.d() does in fact get called. Also, ops is an object of type OptionSelect which happens to be the type of the class in which the onCreate() call is made. Will that become an issue? Also, here is the method for incrementProbability():

public void incrementProbability(int numberOfOptions)
    {
        probability += (numberOfOptions - 1);
        if(probability > 100)
        {
            Log.i("OptionSelect", "Exceeded Maximum by " + (probability - 100));
            probability = 100;
        }
    }

Also, here is relevant code I should’ve included that is updating my GUI at the end of the onClick() method:

    private void refreshDisplay(TextView a, TextView b, TextView c, TextView d)
{
    a.setText(getOptionList().get(0).getProbability() + "");
    b.setText(getOptionList().get(1).getProbability() + "");
    c.setText(getOptionList().get(2).getProbability() + "");
    d.setText(getOptionList().get(3).getProbability() + "");

    a.invalidate();
    b.invalidate();
    c.invalidate();
    d.invalidate();
}

Thanks for the help so far!

  • 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-22T16:03:09+00:00Added an answer on May 22, 2026 at 4:03 pm

    I personally prefer to have my Activities implement listener interfaces and add an onClick method to the Activity itself such as…

    public class MyActivity extends Activity
        implements View.OnClickListener {
    
        ...
    
        @Override
        public void onClick(View v) {
    
            ...
    
        }
    }
    

    I then just use…

    myGuiObject.setOnClickListener(this);
    

    …whenever I want to set that method as the listener for any GUI object.

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

Sidebar

Related Questions

Once again a very beginner-ish question, but here I go: I would like to
I might be asking a very basic question and I am sorry for that.
My apologies once again for asking another very junior question. For one reason or
Found this question but there is no proper answer, so asking again. How do
I have a very basic question how the creation of HTTPSession works.I know you
This may be a very old, many times asked question. But I am not
This is a follow up to my other question . I am asking again
This question didn't receive any satisfactory answers, so I'm asking again. I can get
Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
Hello again ladies and gents! OK, following on from my other question on ASP.NET

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.