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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:46:37+00:00 2026-05-27T14:46:37+00:00

I currently have a list view and I’m trying to direct the list view

  • 0

I currently have a list view and I’m trying to direct the list view to different activities. So that if you click an item from let’s say 1-4 you’ll get the class that corresponds to that. The only way that I can think of doing it is grabbing the text of the item in the list view and starting the activity of that name. The code for it would go something like this:

final String chosen = "";
chosen = (String) ((TextView) view).getText();
Intent nextScreen = new Intent(getApplicationContext(), chosen.class);

That does not work. I get an error on the last line, saying that chosen cannot be resolved into a type.

I know that ((TextView) view).getText() works because

Log.d("Debug", "Test"+((TextView) view).getText());

gives me the correct chosen item in logcat.

Any ideas/suggestions? Thanks in advance

EDIT:

I tried changing my code to this:

String chosen = (String) ((TextView) view).getText();
try {
    Intent nextScreen = new Intent(getApplicationContext(), Class.forName(chosen));
    startActivity(nextScreen);
    Log.d("Debug", "Good"+((TextView) view).getText());
    } 
catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    Log.d("Debug", "Bad"+((TextView) view).getText());
    }
    Log.d("Debug", "Final"+((TextView) view).getText());

Log cat gave me an output of

BadItem1
FinalItem1

I think I’m going about this the wrong way as someone pointed out. I also think I should be using OnItemClickListener. I will try it and post my results for easier help in the future.

  • 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-27T14:46:38+00:00Added an answer on May 27, 2026 at 2:46 pm

    The error is here:

    final String chosen = "";
    chosen = (String) ((TextView) view).getText();
    

    Since you declare chosen as final, you can assign it a value only once:

    final String chosen = (String) ((TextView) view).getText();
    

    Moreover I suppose you want to start the Activity which has the name that is stored in variable chosen. You cannot write chosen.class for this. The correct way to do this is:

    Class.forName(chosen);
    

    Hope this helps!

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

Sidebar

Related Questions

I currently have a simple list view adapter that holds two rows of text.
I have currently have the same code from the android list view tutorial. I
On my index/list view I have a list of records from the database, currently
I currently have SP list that contains the following columns. Item, Category & Description
I currently have a list view which has several rows of data and I
I currently have some code that pulls down a list of users in a
Currently I have a list view within it each row has a checkbox attached.
I currently have a view that contains a ListBox bound to a a collection
I am currently stuck on a small problem. I have a List View which
I currently have a stored procedure that returns a list of account numbers and

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.