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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:21:14+00:00 2026-06-14T02:21:14+00:00

I have got a few buttons which users can select and it will display

  • 0

I have got a few buttons which users can select and it will display an image, however it seems to stack the images on top of each other and not deleting the previous image. I have found a similar question here but it still doesn’t seem to work.

here is my Complete code:

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SlidingDrawer;

public class Samples extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.samples);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    final SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.sD2);
    slider.animateOpen();

    Button next = (Button) findViewById(R.id.samplea);
    Button next1 = (Button) findViewById(R.id.sampleb);
    Button next2 = (Button) findViewById(R.id.samplec);
    Button next3 = (Button) findViewById(R.id.sampled);
    Button next4 = (Button) findViewById(R.id.samplee);
    Button next5 = (Button) findViewById(R.id.samplef);
    Button next6 = (Button) findViewById(R.id.sampleg);
    Button next7 = (Button) findViewById(R.id.sampleh);
    Button next8 = (Button) findViewById(R.id.samplei);
    Button next9 = (Button) findViewById(R.id.samplej);
    Button next10 = (Button) findViewById(R.id.samplek);
    Button next11 = (Button) findViewById(R.id.samplel);
    Button next12 = (Button) findViewById(R.id.samplem);
    Button next13 = (Button) findViewById(R.id.samplen);



    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // You can turn this into a class variable
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplea);
            slider.animateClose();
        }
    });

   next1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.sampleb);

        slider.animateClose();
        } 
    });

    next2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplec);
        slider.animateClose();
        } 
    });

    next3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.sampled);
        slider.animateClose();
        } 
    });

    next4.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplee);
        slider.animateClose();
        } 
    });

    next5.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplef);
        slider.animateClose();
        } 
    });

    next6.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.sampleg);
        slider.animateClose();
        } 
    });

    next7.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.sampleh);
        slider.animateClose();
        } 
    });

    next8.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplei);
        slider.animateClose();
        } 
    });

    next9.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplej);
        slider.animateClose();
        } 
    });

    next10.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplek);
        slider.animateClose();
        } 
    });

    next11.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplel);
        slider.animateClose();
        } 
    });

    next12.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplem);
        slider.animateClose();
        } 
    });


    next13.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            final ImageView imageView = (ImageView) findViewById(R.id.iM2);
            imageView.setImageResource(R.drawable.samplen);
        slider.animateClose();

        }
    });
        }
    }

and for xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   <RelativeLayout 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"> 

<ImageView
    android:id="@+id/iM2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart" />

</RelativeLayout>
</ScrollView>

<SlidingDrawer
    android:id="@+id/sD2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:content="@+id/content"
    android:handle="@+id/handle" >

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select Sample" />

    <RelativeLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:background="@drawable/sampleshd">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <Button
                    android:id="@+id/samplea"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:background="@drawable/sampleabutton" />

                <Button
                    android:id="@+id/sampleb"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_marginTop="20dp"
                    android:layout_below="@+id/samplea"
                    android:background="@drawable/samplebbutton" 
                    android:longClickable="true"/>

It just repeats for all the other buttons.

  • 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-14T02:21:15+00:00Added an answer on June 14, 2026 at 2:21 am

    Did you set any background in your xml for this imageView? Because background and src(imageResource) are different… So if you set image’s background in your xml and if you’re setting its resource in your java code, yes you may see more than one image.

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

Sidebar

Related Questions

i have form in drupal which uploads images and has got few checkboxes in
I have got a few tables which I am trying to join. I just
I have an iframe which contains a few select drop-down lists for data entry.
So I have googled whole day, got few answers how to do this, and
I've got a few files that have been serialized by directly writing C++ struct
I have probem / strange question, i got algorithm with few for loops and
I have been working on this for few hours and got stuck, so how
I have looked at Spring MVC a few times briefly, and got the basic
When you click on this link, you can see that the stack overflow will
I have a bunch of Buttons (custom, with a few extra methods to apply

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.