I am trying to get the title of the song that was selected from my listview but I'm getting a forced close. Any ideas?
ArrayList<String>songtitle = new ArrayList<String>();
//This is how i popluated sontitle//
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.song,songtitle);
setListAdapter(adapter);
protected void onListIemClick(ListView , View v, int position, long id){
super.onListItemClick(c, v, position, id);
Object o = this.getListAdapter().getItem(position);
String pen = o.toString();
Toast.makeText(this, "You have chosen the color: " + " " + songtitle, Toast.LENGTH_LONG).show();
selection
is not being updated here, it should be computed based on theposition
. You probably want to something like this:Also, it looks like
songTitle
is a list. You should probably rename that tosongTitles
to begin with. Check that the position is within the bounds of your list. What kind of error are you getting?try this.