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

The Archive Base Latest Questions

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

I have following goal: From a list in main activity that extends ListActivity, I

  • 0

I have following goal: From a list in main activity that extends ListActivity, I want to start other activities.

This is the code of the main activity:

public class SelectionWidgetsExampleActivity extends ListActivity {

    private Class[] demos = {ListViewDemo.class, ChecklistDemo.class};
    private ArrayAdapter<Class> aa;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        aa = new ArrayAdapter<Class>(this, android.R.layout.simple_list_item_1, demos);
        setListAdapter(aa);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Intent intent = new Intent(this, demos[position]);
        startActivity(intent);
    }
}

My question is

How would you solve the issue of having list of classes to be executed outside the code of the main activity?

My first idea was to put it into xml resource file as string array. I can then easily create array of Strings from the resource, but don’t know how to convert the string to the class – I need something like:

    SomeJavaClass.getMeClassFromString(demos[position])
  • 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:00:32+00:00Added an answer on May 24, 2026 at 5:00 pm

    Do you need Class#forName(String className)?
    It will solve your issue.
    But what’s wrong with your initial (posted) solution? I’d rather keep it than use dynamic class loading, only would changed modifiers of demos to private static final.

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

Sidebar

Related Questions

My goal is to have the url routing as following: http://www.abc.com/this-is-peter-page http://www.abc.com/this-is-john-page What is
I have the following code: $query = mysql_query(SELECT * FROM activity ORDER BY activity_time
I have a Goal model that HasAndBelongsToMany Users. This HABTM is named Participant. When
I have the following database table object: public class Goal { @DatabaseField(generatedId = true)
I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
My goal in the following is to have a Popover appear via one of
I have following script that executes all the .reg files in the current directory.
I have implicitly made this a community wiki seeing that the answers can be
I'm trying to retrieve a list of schedules that occur between a start and
I'm have an issue with this entity query that I am hoping to get

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.