我正在尝试获取从我的列表视图中选择的歌曲的标题,但我正在被迫关闭。有什么想法吗?
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();
答案 0 :(得分:1)
protected void onListIemClick(ListView , View v, int position, long id){
Toast.makeText(this, "You have chosen the color: " + songtitle.get(position), Toast.LENGTH_LONG).show();
}
试试这个。
答案 1 :(得分:0)
selection
此处未更新,应根据position
进行计算。你可能想要这样的东西:
((TextView)v).setText(text);
此外,songTitle
似乎是一个列表。您应该将其重命名为songTitles
以开始。检查位置是否在列表的范围内。你得到了什么样的错误?