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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:13:51+00:00 2026-06-07T16:13:51+00:00

We started an informal Android development group at work. We’ll each be adding semi-independent

  • 0

We started an informal Android development group at work. We’ll each be adding semi-independent Activities to a single app. Goofing around yesterday, the best I could come up with to make this ‘easy’ was to have our main activity be a GridView and allow developers to ‘register’ their Activities in the main Activity via an element in a hard-coded array of ‘ActionItems’:

    private final ActionItem[] actionItems = {
        new ActionItem(R.drawable.dms_to_dd, "DMS to/from DD", DegreeConverter.class)
    };

where an ActionItem is just this:

public class ActionItem {

    private int drawingID;
    private String label;
    private java.lang.Class<?> activity;

    public ActionItem(int drawingID, String label, Class<?> activity) {
        this.drawingID = drawingID;
        this.label     = label;
        this.activity  = activity;
    }

    public int getDrawingID() {
        return drawingID;
    }
    public String getLabel() {
        return label;
    }
    public Class<?> getActivity() {
        return activity;
    }   
}

To get people started I created the first simple Activity/ActionItem and it is registered as shown above.

We want the drawable to be there for the image in the GridView and the String for labeling and, most importantly, the class that will be launched through an Intent when the corresponding GridView item is selected.

All of this works. However, it would be nice if folks didn’t have to edit the main Activity to make this work. I was hoping we could read this same information (for the ActionItem) from a text file before populating the GridView. The drawable id and the String are no problem. So the main question: How might we specify that class in a text file?

Is there someway to create a java.lang.Class instance from a name (String/char[])?
Is there some better way to do what I’ve described above?

Happy to provide further details if 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-07T16:13:54+00:00Added an answer on June 7, 2026 at 4:13 pm

    Have you tried with:

      Class.forName("com.something.MyClass")
    

    http://developer.android.com/reference/java/lang/Class.html#forName(java.lang.String)

    You can read the name from a file, and set the string in the forName method.

    So, you can do something like this:

      public ActionItem(int drawingID, String label, String activityClassName) {
        this.drawingID = drawingID;
        this.label     = label;
        this.activity  = Class.forName(activityClassName);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Started coding up a simple android app. Part of it pulls the users last
I started an ASP.NET MVC 4 app in an old project, then stopped development
I started to work on a very cool Chrome extension and I ran into
I started an application in Google App Engine right when it came out, to
I started using NetBeans for Python development, and so far it looks pretty good.
I started building my app for api 13, because I thougth it could be
Started coming up with a java web app for online user interaction. Decided to
Started using Visual Studio 2012 RC since yesterday, We have one WCF solution. Whenever
Started recently, basically every time I try to fetch or commit it gives me
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like

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.