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.