user1363871
user1363871

Reputation: 570

Android - Listview on click activates a new intent

OK I've been online trying to figure this out, and piecing together bits of code here and there. I still don't understand. All I want is to display three list items and on item click it would go to a new activity. What do I need to fix?

Edit:

I made a stupid mistake. Fixed now - thanks everyone!

Upvotes: 0

Views: 283

Answers (4)

mrketchup
mrketchup

Reputation: 118

You never set the onItemClickListener to the listview:

myList.setOnItemClickListener(this);

Upvotes: 0

digerati32
digerati32

Reputation: 663

Sam and El Duderino both have valid points, but just as an amusing point nonetheless:

You're checking to see if the items are "Economy" "Basic" "Professional", etc., but your String array has only the months of the year ... :P

Also, when setting the Intents, you should not be using this, because you are in the onClick event, which means this is an onClickListener and not an Activity. So use atcList.this instead of just this.

Upvotes: 0

Sam
Sam

Reputation: 86948

I'm going to guess that you should replace this:

String item = (String) getListAdapter().getItem(position);

with this:

String item = view.getText().toString();

getListAdapter() is a function for a ListActivity but not a regular Activity.

Upvotes: 1

El Duderino
El Duderino

Reputation: 509

Are you sure that you have your new activity classes in the android manifest? You need to add each activity you are going to launch to the manifest.

Check your manifest.xml and declare the activities and you should be good to go. Also change the way you get the info from the listener to so that you getString from the item instead of using the position. That way you can control exactly what is passed to your intent by specifying the textview on the item.

Upvotes: 0

Related Questions