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 trying folling code into android tv=(TextView) findViewById(R.id.ringtone); if (!hasErrors) { setListAdapter(new ArrayAdapter<String>(FindFilesByType.this,
I am new to Android development and running into a bizarre issue for which
I'm fairly new to Android development so I ran into a problem with the
I am new to android development, can any one tell me how to rotate
I'm new in Android development and I wanted to make application that has header,
I'm new into the Android World and I've a problem getting a ImageView value,
I wanted to display my data into android spinner from database. I used two
i am new to android development and i am now developing a project. This
Ok, so I just recently got into this Android app development using Eclipse for
I'm new to Android development. I want to load a html file into 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.