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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:14:25+00:00 2026-06-17T19:14:25+00:00

Possible Duplicate: Button next and prev not working I have 5 buttons in my

  • 0

Possible Duplicate:
Button next and prev not working

I have 5 buttons in my layout and on the next button i want to change the text of the button which is from a arraylist. how could i implement this?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center_horizontal"
android:orientation="vertical" >

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b1"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="1" />
    </LinearLayout>

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b2"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="2 />
    </LinearLayout>

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b3"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="3" />
    </LinearLayout>

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b4"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="4" />
    </LinearLayout>

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b5"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="5" />
    </LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:enabled="false"
        android:text="Prev" />

    <Button
        android:id="@+id/right"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:text="Next" />
</LinearLayout>

my java class::
here count is the static variable.

public void onClick(View arg0) {
    String a=null;
    switch(arg0.getId()){
    case R.id.left:


        if( count==0)
            prev.setEnabled(false);
        else{
             count--;

        }
        break;
    case R.id.right:
        if( count>5)
            next.setEnabled(false);
        else{
             count++;

        }
        break;
    case R.id.b1:

            a=(( count*0)+0)+"";
            bb1.setText(a);
        }
        break;
    case R.id.b2:

            a= (( count*0)+1)+"";
            bb2.setText(a);
        }
        break;
    case R.id.b3:

            a= (( count*0)+2)+"";
            bb3.setText(a);
        }
        break;
    case R.id.b4:

            a= ((count*0)+3)+"";
            bb4.setText(a);
        }
        break;
    case R.id.b5:

            a= ((count*0)+4)+"";
            bb5.setText(a);
        }
        break;

    }
}

i want the button text to be changed by the value of count. but the values are not changing.
my doubt is that is there a need to refresh the acctivity after every click of next and prev

  • 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-17T19:14:26+00:00Added an answer on June 17, 2026 at 7:14 pm

    The problem is, you are trying to change the Text of the Buttons in the Click Event of their self.

    So, when you click next or prev, the text in the buttons won’t change(only count changes). They only change(actually updated with latest count values) when you click on them(b1,2,3,4,5).

    So, to get what you required do this:

    public void onClick(View arg0) {
    String a=null;
    switch(arg0.getId()){
    case R.id.left:
    
    
        if( count==0)
            prev.setEnabled(false);
        else{
             count--;
             //You want to change the text(count) of button1,2,3,4,5 when you click prev.
             //So, do that here
    
    bb1.setText("" + count);
    bb2.setText("" + count);
    bb3.setText("" + count);
    bb4.setText("" + count);
    bb5.setText("" + count);
    
             //Similarly on next clicked
    
        break;
    case R.id.right:
        if( count>5)
            next.setEnabled(false);
        else{
             count++;
    bb1.setText("" + count);
    bb2.setText("" + count);
    bb3.setText("" + count);
    bb4.setText("" + count);
    bb5.setText("" + count);
    
        break;
    case R.id.b1:
            //here don't change any text, just check the text value and call the respective answer
           if(bb1.getText == "5"){
              //call answer5 etc..,
              }
    
              //do the same with other buttons b2,3,4,5
        break;
    case R.id.b2:
    
            a= (( count*0)+1)+"";
            bb2.setText(a);
    
        break;
    case R.id.b3:
    
            a= (( count*0)+2)+"";
            bb3.setText(a);
    
        break;
    case R.id.b4:
    
            a= ((count*0)+3)+"";
            bb4.setText(a);
    
        break;
    case R.id.b5:
    
            a= ((count*0)+4)+"";
            bb5.setText(a);
    
        break;
    
    }
    

    }

    by which you are changing the text of the buttons on click of the next and prev buttons

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

Sidebar

Related Questions

Possible Duplicate: How to change button text for Yes & No buttons on MessageBox.Show
Possible Duplicate: how to delete row from datagridview with a delete button? I have
Possible Duplicate: Calling A Button OnClick from a function I want to do button
Possible Duplicate: Text on an Image button in c# asp.net 3.5 I have an
Possible Duplicate: ios making a button change view when text field equals string I
Possible Duplicate: How to Change color of Button in Android when Clicked? I want
Possible Duplicate: Toggle button and Toggle visibility I have a piece of text on
Possible Duplicate: button javasript works on IE but not firefox window.navigate() I want pass
Possible Duplicate: Prevent Back button from showing POST confirmation alert I have used the
Possible Duplicate: Previous/next Buttons? how can i make next page and prev page in

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.