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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:08:30+00:00 2026-05-26T13:08:30+00:00

In my project I’m trying to display several image files by manipulating the filename

  • 0

In my project I’m trying to display several image files by manipulating the filename of one of the images programatically.

ie, I may have:
filename.jpg, filename_top.jpg, filename_middle.jpg

I receive input of an drawable int and am trying to find the filename of the displayed image before manipulating this filename and trying to display the programatically generated filenames.. problem is that the manipulated filename does not display.
ie. there is something wrong with this:
imageView2.setImageResource(getImageId(this, namebottom));

Any ideas how getImageId can be modified to make setImageResource work properly?

The code would look something like this:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle bun = getIntent().getExtras();
int imagenumber = bun.getInt("imagenumber");
String extension = bun.getString("extension");
// int become a val from 0 to 20 (array size)
setContentView(R.layout.clickeditem);

final int[] imgIds = new int[{
R.drawable.image0,R.drawable.image1,R.drawable.image2,,,R.drawable.image20};

//The first image with id top in the layout is set ok:
ImageView imageView1 = (ImageView)findViewById(R.id.top);
imageView1.setImageResource(imgIds [ imagenumber ] );
// problem here:
//try to get the name of this file: ie: filename.jpg
//       and then manipulate the filename:
String name = imageView1.getResources().getString(R.id.image0); 
//try to convert this to the filename_middle.jpg         
String namemiddle = name.replace(".jpg", "_middle.jpg");
imageViewt.setImageResource(getImageId(this, namemiddle)); 

//try to convert this to filename_bottom.jpg
String namebottom = name.replace(".jpg", "_bottom.jpg");
imageView2.setImageResource(getImageId(this, namebottom)); 
}

//where getImageId is defines as follows:
public static int getImageId(Context context, String imageName) 
{
return context.getResources().getIdentifier("drawable/" + imageName,
 null, context.getPackageName());
}
  • 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-26T13:08:30+00:00Added an answer on May 26, 2026 at 1:08 pm
    return context.getResources().getIdentifier("drawable/" + imageName,
     null, context.getPackageName());
    

    replace this by

    return context.getResources().getIdentifier(imageName,
     "drawable", context.getPackageName());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My project has two cpp files and one header file. One cpp file contains
My project is ARC enabled (the build settings have Objective-C Reference Counting set to
My project have no visible error but when i try to run it gives
Project I'm working on uses jQuery. I have a series of Ajax calls being
Project Euler I have recently begun to solve some of the Project Euler riddles.
Project : ASP.NET 3.5 Server : SQL Server 2008 One of the page in
Project file here if you want to download: http://files.me.com/knyck2/918odc So I am working on
Project is C#. So I have a bunch of multithreaded code that is designed
Project Structure I have a silverlight project SLProj, that references a silverlight class library
Project: Winforms, .NET framework: 3.5 (Visual Studio 2008) My problem is: I have 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.