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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:12:36+00:00 2026-06-04T19:12:36+00:00

I have a button to which I attach an onClickListener via code. I have

  • 0

I have a button to which I attach an onClickListener via code. I have to to this through code because it’s in a fragment.

The listener works fine when in landscape mode, but when it’s in portrait it doesn’t. There’s no “click” sound even.

In my xml file, I set the initial visibility of the button to invisible and then make it visible later when the user clicks a radio button in the same Viewgroup as the button. The onclicklisteners of the radiobuttons are working just fine in both portrait and landscape mode.

Now if I remove the “android:visibility=”invisible” code in xml, the onclickstener works fine in portrait mode! But of course I need it invisible till the user clicks a radiobutton otherwise the UI doesn’t make sense. Very weird indeed.

Here’s my code:

private void setOnClickForSaveButton(View v) {

        Button changeFundsSave = (Button) v.findViewById(R.id.change_funds_save);
        changeFundsSave.setOnClickListener(saveListener);

    }

Button.OnClickListener saveListener = new Button.OnClickListener() {

        @Override
        public void onClick(View v) {

            //Get the rootview
            View rootView = v.getRootView();

            EditText changeFundsEdit = (EditText) rootView.findViewById(R.id.change_funds_edit);

            if(changeFundsEdit.getText().toString().equals("")) {
                new AlertDialog.Builder(getActivity())
                .setTitle( "" )
                .setMessage( "Enter the number of units" )
                .setPositiveButton( "Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {


                    }
                })
                .show();
                return;


            }


        }
    };


    private void setOnClicksForRadioButtons(View v) {

        RadioButton rb1 = (RadioButton)v.findViewById(R.id.add_units);
        RadioButton rb2 = (RadioButton)v.findViewById(R.id.remove_units);
        RadioButton rb3 = (RadioButton)v.findViewById(R.id.set_units);

        rb1.setOnClickListener(addRemoveSetButtonListener);
        rb2.setOnClickListener(addRemoveSetButtonListener);
        rb3.setOnClickListener(addRemoveSetButtonListener);

    }





    OnClickListener addRemoveSetButtonListener = new OnClickListener() {

        @Override
        public void onClick(View v) {

            // Since we only have the radiobutton view, we need to get the parent
            View rootView = v.getRootView();

            //Make the controls visible
            TextView changeFundsText = (TextView) rootView.findViewById(R.id.change_funds_text);
            EditText changeFundsEdit = (EditText) rootView.findViewById(R.id.change_funds_edit);
            Button changeFundsSave = (Button) rootView.findViewById(R.id.change_funds_save);

            changeFundsText.setVisibility(View.VISIBLE);
            changeFundsEdit.setVisibility(View.VISIBLE);
            changeFundsSave.setVisibility(View.VISIBLE);


        }

    };


}
  • 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-04T19:12:38+00:00Added an answer on June 4, 2026 at 7:12 pm

    Solved the problem! In portrait mode, like everyone else I load one fragment in a separate activity. Out of habit I was calling setContentView(something) before loading the fragment! So ultimately the two layouts were overlapping each other and the visible and invisible buttons were overlapping each other and things must have gotten messed up. Damn, I’m not sure if I like the concept of fragments at all. My first time using them. But maybe I just need to learn how to wire them up properly before I get used to them 🙂 Thank you so much for your help

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

Sidebar

Related Questions

I have a button which when toggled displays/hides a div ('.reportOptions'), this works perfectly
I have this button which is not working correctly for hold button for a
I have a button which triggers the function inside set interval every 1 sec.
I have a button which is in update panel. When I click on button
I have a button which opens a context menu with a list of various
I have a button which creates a div. Once clicked I would like to
I have a Button which when clicked will execute an addQty method and in
I have a button which when pressed, sets the user's rights in the db.
I have one problem with my jPanel. I have a button which PNG image
On my website, I have a button which when clicked displays a feedback form

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.