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

  • Home
  • SEARCH
  • 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 7434309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:48:55+00:00 2026-05-29T09:48:55+00:00

I have a doubt in android ImageView . I’m making a sample application to

  • 0

I have a doubt in android ImageView. I’m making a sample application to display the image in my drawable folder. First of all i used Galleryview and Imageview in my Layout to display the images, when i click the image in GalleryView the corresponding images is displayed in ImageView. Now i wish to implement like this, enter image description here

That is, I have set of 10 images in my res/drawable folder, the images will displayed among the corresponding button click, if i click Front button, the images in ImageView will displayed in forward manner, else i click Back button the images in ImageView moves Backward. is it possible to do like this.

I used the following code, but the image won’t display

main.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" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="fill_parent"
        android:layout_height="333dp"
        android:src="@drawable/ic_launcher" />

    <Gallery
        android:id="@+id/galleryView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <Button
            android:id="@+id/backBTN"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="B" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="imagePosition"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Button
            android:id="@+id/frontBTN"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/backBTN"
            android:layout_alignBottom="@+id/backBTN"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="F" />
    </RelativeLayout>

</LinearLayout>

My Java code MainActivity.java is,

package com.test.button.wallpaper;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    Button front, back;
    ImageView mImage;
    Gallery mGallery;
    int image_postion;
    private int[] gal = { R.drawable.img_2, R.drawable.img_3, R.drawable.img_4,
            R.drawable.img_5 };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        front = (Button) findViewById(R.id.frontBTN);
        back = (Button) findViewById(R.id.backBTN);
        mImage = (ImageView) findViewById(R.id.imageView);
        mGallery = (Gallery) findViewById(R.id.galleryView);
        mGallery.setAdapter(new ImageAdapter(this));
        mGallery.setVisibility(View.GONE);
        mGallery.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int loc,
                    long arg3) {
                // TODO Auto-generated method stub
                image_postion = loc;
                System.out.println("Inside the Gallery");

            }
        });

        back.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                int position = mGallery.getSelectedItemPosition();
                if (position < mGallery.getCount() - 1)
                    mGallery.setSelection(position + 1);

            }
        });

        front.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                int position = mGallery.getSelectedItemPosition();
                if (position >= 1)
                    mGallery.setSelection(position - 1);

            }
        });
    }

    public class ImageAdapter extends BaseAdapter {
        private Context ctx;
        int imageBackground;

        public ImageAdapter(Context c) {
            ctx = c;
            // TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
            // imageBackground = ta.getResourceId(
            // R.styleable.Gallery1_android_galleryItemBackground, 1);
            // ta.recycle();
        }

        @Override
        public int getCount() {

            return gal.length;
        }

        @Override
        public Object getItem(int arg0) {

            return arg0;
        }

        @Override
        public long getItemId(int arg0) {

            return arg0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(gal[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(150, 120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }

    }
}
  • 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-29T09:48:55+00:00Added an answer on May 29, 2026 at 9:48 am

    yes, just setSelection to position by

    btnNext.setOnClickListener(new View.OnClickListener()
    {
         public void onClick(View view)
         {
              int position=gallery.getSelectedIndex();
              if(position<gallery.getCount()-1)
                gallery.setSelection(position+1);
         }
    });
    
    
    btnPrevious.setOnClickListener(new View.OnClickListener()
    {
         public void onClick(View view)
         {
              int position=gallery.getSelectedIndex();
              if(position>=1)
                  gallery.setSelection(position-1);
         }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in android application.I have one doubt How long it takes to
I have a doubt regarding application name on Android. I am going to upload
Hi am developing android application. I have some small doubt of how to change
i'm new at Android world, and i have a doubt, is there any method
I have a small doubt regarding network connection procedure in Android. My scenario is
I have some doubts regarding In-Application-Billing in android: Can i test it with different
I have few doubts regarding the 3d Animation Image View on android.i have created
If you own Android phone you are no doubt have noticed how in the
I am new to android, I have a small doubt regarding how to handle
I have a general doubt about how to design Android apps that use a

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.