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

The Archive Base Latest Questions

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

I am creating an app which has two navigation bars at the top: previous

  • 0

I am creating an app which has two navigation bars at the top: “previous” and “next”. I am trying to make it so that the buttons become disabled on the 1st and last page respectively. I am not sure why this code doesn’t work. The previous button becomes disabled but the “next” button does not become enabled(false).

here is my code:

previous =(Button)findViewById(R.id.button_previous);
        next = (Button)findViewById(R.id.button_next);
            previous.setOnClickListener(this);
            next.setOnClickListener(this);

        spinner = (Spinner)findViewById(R.id.spinner);
        heading = (TextView)findViewById(R.id.textNavigationHeading);
        text = (TextView)findViewById(R.id.textNavigationText); 



        Bundle ext = getIntent().getExtras();
        this.list = ext.getInt("list");
        this.page = ext.getInt("page");

        if(list == 0){
            itemsHeading = campaignHeadings;
            MAX_PAGES = campaignHeadings.length;
        }

        if(list == 1){
            itemsHeading = specopsHeadings;
            MAX_PAGES = specopsHeadings.length;
        }

        setContent();       
    }

    private void setContent() {
        heading.setText(itemsHeading[page]);
        text.setText("Blah blah blah");     
        checkButtons(page);
    }

    private void checkButtons(int page) {
        if(page == 0)
            previous.setEnabled(false);
        if(page != MAX_PAGES)
            next.setEnabled(true);
    }

    private void resetButtons(int page){
        previous.setEnabled(true);
        next.setEnabled(false);
        checkButtons(page);
    }

    public void onClick(View v) {

        switch(v.getId()){
        case R.id.button_next:
            page += 1;
            break;
        case R.id.button_previous:
            page -= 1;
            break;
        }
        setContent();
        resetButtons(page);

    }

Thankyou for your help

  • 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:44:35+00:00Added an answer on June 4, 2026 at 7:44 pm

    The code which enables and disables the buttons is the following:

    private void checkButtons(int page) {
        if(page == 0)
            previous.setEnabled(false);
        if(page != MAX_PAGES)
            next.setEnabled(true);
    }
    
    private void resetButtons(int page) {
        previous.setEnabled(true);
        next.setEnabled(false);
        checkButtons(page);
    }
    

    You have two different methods, and you call sometimes one, and sometimes the other. Make it one single method, which would look like this:

    private void enableOrDisableButtons(int page) {
        previous.setEnabled(page != 0);
        next.setEnabled(page != (MAX_PAGES - 1));
    }
    

    Also, note that MAX_PAGES is the length of your list, and indices go from 0 to length - 1 inclusive. So the next button needs to be disabled when the page is MAX_PAGES - 1.

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

Sidebar

Related Questions

i am creating an app which has two UIImageViews at top and bottom of
I'm creating an app which has a text field & go button on top
I'm creating an app that has the feature of adding two profiles/accounts. Each profile
I am creating an app which has around 15 different animations. Some animations are
I'm creating a Django app in which I have a table which has 'items',
I am in the process of creating an app which requires irregular shaped buttons.
I am creating an app, in which I have two small imageview (using have
I am bit stack with creating two UIViews which are switchable (each UIView has
I am creating an app which has version for both iPhone and iPad, iPad
I am creating a quiz app which has 2 views, MMAppViewController and a subview

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.