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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:22:03+00:00 2026-05-23T07:22:03+00:00

Hi I am new into android development and I am having trouble into this

  • 0

Hi I am new into android development and I am having trouble into this one. I wanted to display the src name of my imageView on a textView when I click a certain Image.
To understand much further here is my hardcode for the image clickListener (hope someone can also help me to improve my coding).

    int ctr = 0;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play);

        //DECLARE CLICK LISTENERS ON OBJECTS
        ImageView ImageView1 = (ImageView)findViewById(R.id.imageView1);
        ImageView1.setOnClickListener(this);
        ImageView ImageView2 = (ImageView)findViewById(R.id.imageView2);
        ImageView2.setOnClickListener(this);
        ...

public void onClick(View v) {
        //CHANGE TEXT VIEW TEXT BASED ON THE CTR VALUE
        TextView TextView1 =(TextView)findViewById(R.id.textView1); 

        //I WANT TO CHANGE THIS ONE TO DISPLAY SRC INSTEAD OF THE CTR VALUE
        TextView1.setText(Integer.toString(ctr)); 
}

There, instead of displaying the ctr value I wanted to display the src name of whatever image I click between the two images I set. I believe it is possible. 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-05-23T07:22:04+00:00Added an answer on May 23, 2026 at 7:22 am

    You can use below method for get name of resource from it’s id:

    /**
             * Determines the Name of a Resource,
             * by passing the <code>R.xyz.class</code> and
             * the <code>resourceID</code> of the class to it.
             * @param aClass : like <code>R.drawable.class</code>
             * @param resourceID : like <code>R.drawable.icon</code>
             * @throws IllegalArgumentException if field is not found.
             * @throws NullPointerException if <code>aClass</code>-Parameter is null.                  
             * <code>String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.icon);</code><br>
             * Then <code>resName</code> would be '<b>icon</b>'.*/
            public String getResourceNameFromClassByID(Class<?> aClass, int resourceID)
                                                    throws IllegalArgumentException{
                    /* Get all Fields from the class passed. */
                    Field[] drawableFields = aClass.getFields();
    
                    /* Loop through all Fields. */
                    for(Field f : drawableFields){
                            try {
                                    /* All fields within the subclasses of R
                                     * are Integers, so we need no type-check here. */
    
                                    /* Compare to the resourceID we are searching. */
                                    if (resourceID == f.getInt(null))
                                            return f.getName(); // Return the name.
                            } catch (Exception e) {
                                    e.printStackTrace();
                            }
                    }
                    /* Throw Exception if nothing was found*/
                    throw new IllegalArgumentException();
            }
    

    For Example of use :

    String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.icon);
    

    Result will be icon

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

Sidebar

Related Questions

I am having trouble getting the Android Development Tools to install. I overcame one
Extreme Android developer newbie here...well, new to Android development, not development in general. I
I am new to java, eclipse, and android development, so I may be missing
I am new for android development. I am trying read and write contacts to
I'm trying to get into android development and I'm going through the tutorials, however
I'm dipping my toes into Android development. I have a project that will interface
I'm new to Android development, and I've been playing around with it a bit.
I am new to both openGL and android development so please forgive me if
I'm pretty new to Android development, but I have some experience with Java and
Im new into that asp.net thing, but here goes. I got at ImageButton, and

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.