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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:04:38+00:00 2026-06-10T06:04:38+00:00

I have a local sqlite database file that looks something like this… _ID |

  • 0

I have a local sqlite database file that looks something like this…

_ID | Color_Name | Image_Name  
1   | Red        | red.png  
2   | Blue       | blue.png  
3   | Green      | green.png  
Etc.

The Image_Name column of the database contains ONLY the file name, NOT the image itself. All images are stored locally in the res/drawable-mdpi directory.

The goal is to have a list that displays the color name and the associated image for that color from the database. For example, the list would look something like this [the plus sign below represents an actual .png image]…

____________________________________________

Red (text only on this line)  
+ (actual red.png image on this line)  
____________________________________________

Blue (text only on this line)  
+ (actual blue.png image on this line)  
____________________________________________

Etc.  

I can get the color name to display, but I can’t figure out how to get the image itself to display. The relevant portion of code for displaying the name is below…

static class ColorHolder {
    private TextView name=null;

     ColorHolder(View row) {             
        name=(TextView)row.findViewById(R.id.colorName);

        }
           void populateFrom(Cursor c, ColortHelper r) {

               name.setText(r.getName(c)) ;
          }
}

The relevant portion of the xml file for BOTH the name & image is below…

<TextView 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:id="@+id/colorName"/>

<ImageView
 android:id="@+id/ImageView00"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:src="@drawable/image1" <!--[NOTE: THIS DEFAULT IMAGE FILE SHOULD BE REPLACED ON THE FLY W/THE CORRECT IMAGE FILE FOR EACH RECORD]-->
  >

None of the other questions I found were helpful in resolving this issue for me. Could someone please help me get this figured out? I would be happy for any help, but it would be especially helpful if you could use my ACTUAL file names / paths / variables / ID’s / etc. (which are given above) in your explanation so that I could most easily follow & understand your response. Pointing me to tutorials may not be helpful as I have already looked at a lot of material but didn’t get this resolved. Thanks!

  • 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-10T06:04:39+00:00Added an answer on June 10, 2026 at 6:04 am

    Use Resources.getIdentifier(String name, String defType, String defPackage)

    Also you don’t need to store the resource image name … just name them the same as the color (as you already have done), just make sure as I show here that they are lower case

    To use your example:

    void populateFrom(Cursor c, ColorHelper r) {
    
        //get the color name from your database (only once)
    
        String strColor = r.getName(c);
    
        // set the text on your TextView as before
    
        TextView clrName = (TextView)findViewById(R.id.ImageView00);
        clrName.setText(strColor);
    
        // get the resource ID - note "name" without extension
    
        int resourceID = context.getResources().getIdentifier(strColor.toLower(),
                "drawable", context.getPackageName());
    
        //get a reference to your imageview and set the image
    
        ImageView clrImage = (ImageView)findViewById(R.id.ImageView00);
        clrImage.setImageResource(resourceID);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone (iOS) app that keeps data in a local SQLite database
I am attempting to insert data into a local SQLITE database file from a
I have a ListView with custom adapter which is populated from local sqlite database.
I have a django application that uses an SQLite database. I use git to
Currently I have this in my settings.py file: DEBUG = True LOCAL = True
I have an sqlite file in the assets folder. I'm using a database manager
So I have a local SQLite table breadcrumbs being created on the Android device.
I have a local Database running on localhost:3306, which I access with MySQL Workbench.
I have an sqlite database whose data I need to transfer over the network,
I am working on a Cocoa application which talks to a local SQLite database

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.