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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:48:20+00:00 2026-06-11T16:48:20+00:00

I am new to Android programming. I am creating a very simple application in

  • 0

I am new to Android programming.
I am creating a very simple application in which I have more than 5 pictures which are static (stored in drawable folder). Now, I have created an activity which is displaying all the pictures in gridView. Suppose, If I click on 2nd position image, it will open a new activity displaying that particular image in full size (using ImageView) mode plus next next/previous button to navigate on the image (It is not necessary that user can start only with first Image, he/she can select any image from the gridView and then navigation will start from that point itself).
My problem is, I don’t want to harcode the number of switch cases equal to number of images to navigate through the buttons. Is there any other way to implement the required scenario? Or any other feature of Android that I can use to achieve the same?

Thanks in advance!!!

I am adding my code also (First Activity):

public class GridViewActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid_view);
    GridView gridview = (GridView) findViewById(R.id.gridView);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            //Create an Intent
            Intent intent = new Intent(getApplicationContext(), FullImageActivity.class);
            intent.putExtra("image", position);
            startActivity(intent);
        }
    });
}

}

Second Activity:

public class FullImageActivity extends Activity implements OnClickListener {

Button button;
int drawable;
ImageView display;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_image);
Intent intent = getIntent();
display = (ImageView) findViewById(R.id.fullImageView);

ImageView imageView = null;

String idName = "ivImage";
int id;
for (int i = 1; i <= 2; i++) {
id = getResources().getIdentifier(idName + i, "id",
getPackageName());
imageView = (ImageView) findViewById(id);
imageView.setTag((Integer) i);
imageView.setOnClickListener(this);
if (i == 1) {
// make sure that your "drawable" has a value different than 0!
// otherwise a click on setWall button might result into a crash
drawable = id;
}
}
int pos = intent.getExtras().getInt("image");
ImageAdapter imageAdapter = new ImageAdapter(this);

imageView.setImageResource(imageAdapter.mThumbIds[pos]);
Log.i("pos", "" + pos);
// System.out.println("pos: " + pos);

button = (Button) findViewById(R.id.btnNextScreen);
button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
InputStream inputStream = getResources().openRawResource(
drawable);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

try {
getApplicationContext().setWallpaper(bitmap);
} catch (IOException e) {
// use Log.e() with all 3 params instead of
// e.printStackTrace();
Log.e("MyTag", "couldn't set wallpaper", e);
}
}
});

}

@Override
public void onClick(View v) {
// just to make sure that the clicked view is a ImageView
if (v instanceof ImageView) {
ImageView imageView = (ImageView) v;
int place = (Integer) imageView.getTag();
int drawableId = getResources().getIdentifier("image" + place,
"drawable", getPackageName());
display.setImageResource(drawableId);
drawable = drawableId;
}

}

}

I have added that code what @WarrenFaith has suggested me. After adding suggested code, it is throwing me an error on “imageView.setTag((Integer) i);”. PLease tell me where I am going wrong.

  • 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-11T16:48:21+00:00Added an answer on June 11, 2026 at 4:48 pm

    I just answered a question where the goal was to get the hardcoded stuff dynamically.
    It is not exactly your type of app but the basic idea behind my answer should give you the right direction.

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

Sidebar

Related Questions

I'm really new in Android programming, so I have a simple question getting a
New to android programming. I have a layout XML, to which I want to
I'm new to Android programming. What is a simple example showing a custom toast
I'm fairly new to Android programming, so this may be a simple question, but
i am new to android programming. in my application if i press a backbutton
I'm very new to Android programming, so this is probably something pretty basic. I
I'm new on android programming and i'm working on android application and i'm stuck
I'm new to android programming and i have a question I'm developing an alarm
I'm new to Android programming and I've coded a simple game where two players
I am new to Android programming. I have installed the Eclipse and Android SDK.

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.