androidlistviewbuttonsimplecursoradapter

start a new activity from button click within listview (using simplecursoradapter)


I have a listview which I am populating with a custom SimpleCursorAdapter, each row contains a button which, when clicked should open a new activity and pass the ID of the original data object so I can display the related image on screen.

I am having problems implementing the onclick event for the button and I understand you can only use startActivity() within an activity - is this correct? if so, is there a workaround as my cursoradapter code is in it's own class which extends SimpleCursorAdapter (ie. not in an activity!)

Just one more question if I may? - how can I pass the dataobject ID (ImageID) of the button clicked to the new activity?


Solution

  • set click listener over Button in getView() method in your adapter and use startActivity from there.