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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:25:22+00:00 2026-05-24T17:25:22+00:00

The text on my views represent an id. So when clicked I would like

  • 0

The text on my views represent an id. So when clicked I would like to get a reference to that resource. The following incorrect code represents what I’m trying to do

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.categories);

    Bundle bundle = getIntent().getExtras();
    int myArrayID = bundle.getInt("category_id", 0); 
    String [] myArray = getResources().getStringArray(myArrayID);

    setListAdapter(new CategoryAdapter(this, android.R.layout.simple_list_item_1, R.id.categoryText, myArray)); 
    ListView lv = getListView();
      lv.setTextFilterEnabled(true);

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
            String myIdString = (String) ((TextView) view.findViewById(R.id.categoryText)).getText();
            int myIdInt = // convert to the correct id that is represented by this string myIdString
            Intent intent = new Intent(Categories.this, Categories.class);
            intent.putExtra("category_id", myIdInt);
            startActivity(intent);
        }
      });
}

I understand why this method doesn’t work. For example the view would have the text “example1” and then there would be an R.id.example1 value that I need to get a reference to. Obviously I am approaching this the wrong way, and would like some guidance.

Edit – more code as requested.

Edit2 – Poor description. So my activity is a custom list. When one of the views is clicked, the title of that item will correspond to a string-array I have in my strings.xml. So if “example1” is pressed, there will be a string-array with the id R.array.example1. I want my code to extract the text of the view, and use it to find the correct string-array. This string-array would then be used to populate a new activity, with the custom list items the items in the array

  • 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-24T17:25:23+00:00Added an answer on May 24, 2026 at 5:25 pm

    I didn’t get exactly what your code is supposed to do. But to get a resource id out of the resource name, use the following

    getResources().getIdentifier(<resource name>, "id", getPackageName())
    

    Read more here.

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

Sidebar

Related Questions

Please kindly help me in the following, I have $sub = C:\views\sght\gzad\text\hksdk\akldls\hool.java = C:\views\sght\bdsk\text\hksdfg\sdjks\same.java
I have a few views that each have several XAML TextBox instances. The Text
var id = 'test'; var dom = $('#loader').clone().load(Views/chatBox.html); dom.find('span.bn').text(id); in chatBox.html,there is : ...
is there any way to send whats in a text view (im trying to
i am using below code to change the the font type of text view.
I have this layout that works correctly, a relative layout with a text view
I have the following setup, and the empty view text doesn't show up... protected
I'm trying to implement a Page Control to show some pages with the following
I have a layout with 8 buttons 2 image views and 2 text views.
My class extends SimpleCursorAdapter. In that class I try to get CallLog into ListView

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.