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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:16:38+00:00 2026-06-16T09:16:38+00:00

I’m having this problem. I created an activity with two Buttons and a TextView.

  • 0

I’m having this problem. I created an activity with two Buttons and a TextView. The TextView is changed by pressing the Button “Next” and the Button “Previous” is used to change the TextView back to its original (which is textview1). But when “Previous” is pressed while textview1 is displayed or when “Next” is pressed while textview2 is displayed, the application gets an error and is shut down as a consequence. What I want to achieve now is to make the Button “Previous” disappear when textview1 is on and the Button “Next” when textview2 is on.

This is class I currently use:

package com.example.test8;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.TextView;

public class Main extends Activity {
    private static final String[] Texts= 
        {"textview1",
         "textview2"
        };

int textIdx = 0;

TextView Text;
ImageButton Next;
ImageButton Previous;

public static String getText(int idx) { 
    return Texts[idx]; 
} 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final TextView text = (TextView) findViewById(R.id.text);
    ImageButton Next = (ImageButton) findViewById(R.id.Next);
    ImageButton Previous = (ImageButton) findViewById(R.id.Previous);
    Text.setText(getText(textIdx));

    Next.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View v) { 
        textIdx++; 
        Text.setText(getText(textIdx)); 
        } 
    }); 

    Previous.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        textIdx--;
        Text.setText(getText(textIdx)); 
        }
        });

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

I thought about using an else if statement, but I couldn’t make it work, because I lack the knowledge and experience. If someone could help me out here, that would be great. Thanks in advance.

  • 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-16T09:16:39+00:00Added an answer on June 16, 2026 at 9:16 am

    You should disable the buttons to prevent a user from clicking it when there is nothing ahead or behind it in your array.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
    
       final TextView text = (TextView) findViewById(R.id.text);
       ImageButton Next = (ImageButton) findViewById(R.id.Next);
       ImageButton Previous = (ImageButton) findViewById(R.id.Previous);
       Text.setText(getText(textIdx));
    
       Previous.setEnabled(false); //defaults the button to disabled
    
       Next.setOnClickListener(new View.OnClickListener() {  
           public void onClick(View v) { 
           textIdx++; 
           Text.setText(getText(textIdx));            
           Previous.setEnabled(true);
           if(textIdx>=Text.length-1)
              Next.setEnabled(false);  
           } 
       }); 
    
       Previous.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
           textIdx--;
           Text.setText(getText(textIdx));            
           Next.setEnabled(true);
           if(textIdx<=0)
              Previous.setEnabled(false);
           }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.