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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:38:18+00:00 2026-05-28T20:38:18+00:00

I am using two buttons, one for next news and one for previous news.

  • 0

I am using two buttons, one for next news and one for previous news. In my activity when I am on the first news my button should set the image with the grey image and when I move forward my previous news button should change from the grey image to the colored one. Similarly when I reach at the last news my next button should change to grey image.

This is my xml file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFFFF" 
    >

    <TextView
        android:id="@+id/tv_submitDate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Medium Text"
        android:textColor="#000000" 
        android:padding="5dp"/>

    <TextView
        android:id="@+id/tv_headline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_submitDate"
        android:text="Medium Text"
        android:textColor="#000000"
        android:textStyle="bold" 
        android:padding="5dp"/>

    <View
        android:id="@+id/viewSeperator"
        android:layout_width="fill_parent"
        android:layout_height="2dip"
        android:layout_below="@+id/tv_headline"
        android:background="#FF909090" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btn_relative_layout"
        android:layout_below="@+id/viewSeperator" android:padding="10dp">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/tv_detailNews"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Medium Text"
                android:textColor="#000000" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/btn_relative_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#DCDCDC"
        android:padding="10sp" >


        <Button
            android:id="@+id/btn_prevNews"
            android:layout_width="120sp"
            android:layout_height="40sp"
            android:layout_weight="0.5"
            android:layout_marginRight="5sp"
            android:background="@drawable/arrow_left"
            android:clickable="true" />


        <Button
            android:id="@+id/btn_nextNews"
            android:layout_width="120sp"
            android:layout_height="40sp"
            android:layout_marginLeft="5sp"
            android:layout_weight="0.5"
            android:background="@drawable/arrow_right"
            android:clickable="true" />
        </LinearLayout>


</RelativeLayout>

This is where I am trying to change the image of my button:

public void onClick(View v) {

        if (v == btnPrevNews && newsId > 0) {
            if (newsId > 0) {
                newsId--;
                putDetailNewsinView(newsId);
            } else if (newsId == 0) {
                btnPrevNews
                        .setBackgroundResource(R.drawable.disable_arrow_left);
                btnPrevNews.setEnabled(false);
            }
            // btnPrevNews.setVisibility(View.INVISIBLE);

        } else if (v == btnNextNews && newsId < newsListDetail.size() - 1) {
            if (newsId < newsListDetail.size() - 1) {
                newsId++;
                putDetailNewsinView(newsId);
                if(newsId == 0)
                    btnNextNews.setBackgroundDrawable(getResources().getDrawable(
                            R.drawable.disable_arrow_right));
            } else if (newsId == newsListDetail.size()) {
                // btnNextNews.setVisibility(View.INVISIBLE);
                btnNextNews.setBackgroundDrawable(getResources().getDrawable(
                        R.drawable.disable_arrow_right));
                // btnNextNews.setBackgroundResource(R.drawable.disable_arrow_right);
                btnNextNews.setEnabled(false);
            }
        }

    }

Please help me out in this.

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-05-28T20:38:18+00:00Added an answer on May 28, 2026 at 8:38 pm

    I assume you have Methods which will be executed if the Button is pressed. Just use these and add Logic to change the Background of these Buttons to grey:
    Give both Buttons an ID, you can access these Buttons with:
    Button mybutton = (Button) findViewById(R.id.yourid);

    Now you can do all kinds of things with your button, like changing the background.

    edit:
    The Problem could lay in the Pictures, but if i were you, i would set some breakpoints and debug step-by-step.

    I hacked some code of mine to test this functionality, it works fine for me. Here is it:

        package my.namespac;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class SomeTestProjectActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Button button = (Button)findViewById(R.id.btn_prevNews);
    
            button.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Button b = (Button)v;
                    v.setBackgroundDrawable(getResources().getDrawable(R.drawable.koala));
    
                }
            });
        }
    }
    

    And the Layout-Xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    
                <Button
                android:id="@+id/btn_prevNews"
                android:layout_width="120sp"
                android:layout_height="40sp"
                android:layout_weight="0.5"
                android:layout_marginRight="5sp"
                android:background="@drawable/ic_launcher"
                android:clickable="true" />
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two forms. First one is to decide button numbers by using jslider.
i am using following code to display remote image with next and previous buttons.
I'm using two functions one is from this site http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ and its using function
I have created an alert view with two buttons using the following code: UIAlertView
Here i am using a radio button to calculate the date difference between two
I currently am using two stylesheets to get my intended output. The first stylesheet
I'm using two different version of php on two different OS's. One is 5.2.9
I have two submit buttons and one form. How do I check what submit
I want to have three radio buttons, two on one line and one on
I am using two forms, where one is a rich text editor with menus

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.