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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:05:23+00:00 2026-06-14T07:05:23+00:00

I have a ListActivity when clicked, I get the display text that was clicked

  • 0

I have a ListActivity when clicked, I get the display text that was clicked on. Is there a better way, such as using a unique identifier?

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="adjustments">
        <item>Item 1</item>
        <item>Item 2</item>
        <item>Item 3</item>
    </string-array>
</resources>

I then have this as the code:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    String[] adjustments = getResources().getStringArray(R.array.adjustments);
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, adjustments));
    getListView().setTextFilterEnabled(true);
}

protected void onListItemClick(ListView l, View v, int position, long id){
    super.onListItemClick(l, v, position, id);
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    try{
        bundle.putString("adjustment", l.getItemAtPosition(position).toString());
        intent.putExtras(bundle);
        setResult(RESULT_OK, intent);
    }catch(Exception e){
        setResult(RESULT_CANCELED, intent);
    }
    finish();
}

What I would then like to do is give each item a unique identifier instead of getting it’s text to decide what to do next. Is it at all possible? Each option will have the same methods called once clicked using reflection, so if I can call the method once instead of doing 100’s of if/else statements to check to see what was clicked that would be very helpful!

  • 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-14T07:05:24+00:00Added an answer on June 14, 2026 at 7:05 am

    What I did was used the return text to call a class using Reflection. So if the return text was Adjust RGB I would then remove the spaces and initiate the class AdjustRGB and run functions based on an implementation.

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

Sidebar

Related Questions

I have a ListActivity and I want to set programmatically the text of a
I have two ListActivity classes that I want to pass into into a third
I have a ListActivity which has an adapter that crashes. Here is the code
I have the following XML layout for a ListActivity. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a ListView in a ListActivity populated with strings. However, only the text-part
Is there any way i can make my listactivity (rather listview) highlight the List
I have a listactivity where I read/set diferent controls such as textviews, buttons or
I have an Android ListActivity that is backed by a database Cursor through a
I have a ListActivity class, and when any item on the list is clicked,
In an Android project I am working on I have a ListActivity that is

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.