嗨,我需要在 listview 中显示音乐文件数组,当我单击该音乐文件时,我需要播放那首歌曲,我尝试使用下面的代码在 listview 中显示歌曲,但在将数组添加到 textview 行时显示空指针异常,但是用于在列表视图中显示图像的相同代码,我确实误会了任何人建议我..
public class CustomListViewExample extends Activity {
Integer[] text;
public static ArrayList<Integer> list1 = new ArrayList<Integer>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.citylist);
list1.add(R.raw.apple);
list1.add(R.raw.intro_letter_report_card);
list1.add(R.raw.intro_title_page_1);
text = list1.toArray(new Integer[list1.size()]);
ListView l1 = (ListView) findViewById(R.id.ListView01);
l1.setAdapter(new MyCustomAdapter(text));
}
class MyCustomAdapter extends BaseAdapter {
Integer[] data_image;
MyCustomAdapter() {
data_image = null;
}
MyCustomAdapter(Integer[] text) {
data_image = text;
}
@Override
public int getCount() {
return data_image.length;
}
@Override
public String getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.city_row_item, parent, false);
TextView t1=(TextView)row.findViewById(R.id.textView1);
t1.setText(""+data_image[position]);
return (row);
}
}
}