public class ViewActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); ListView listview=(ListView)findViewById(R.layout.list); GetList getlist=new GetList(); List<Map<String, Object>> fileInforList = getlist.MusicInfos(this.getContentResolver()); SimpleAdapter adapter=new SimpleAdapter(this,fileInforList,R.layout.item,new String[]{"name","time"},new int[]{R.id.name,R.id.time}); listview.setAdapter(adapter); } public class GetList { private String selection=MediaStore.Audio.Media.IS_MUSIC+"!=0"; private String[] projection={MediaStore.Audio.Media._ID,//歌曲ID MediaStore.Audio.Media.TITLE,//歌曲标题 MediaStore.Audio.Media.ALBUM,//歌曲专辑 MediaStore.Audio.Media.ARTIST,//歌手 MediaStore.Audio.Media.DURATION,//播放时间 MediaStore.Audio.Media.SIZE,//文件大小 MediaStore.Audio.Media.DATA//文件路径 }; private Cursor cursor=null; public List<Map<String,Object>> MusicInfos(ContentResolver cr) { cursor=cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null); List<Map<String,Object>> listinfos=new ArrayList<Map<String,Object>>(); if(cursor==null) { return null; } else { while(cursor.moveToNext()) { Map<String,Object> map=new HashMap<String,Object>(); map.put("name", cursor.getString(1)); map.put("album",cursor.getString(2)); map.put("singer",cursor.getString(3)); map.put("time", cursor.getString(4)); map.put("data", cursor.getString(6)); listinfos.add(map); } } return listinfos; } } }
运行时老是提示stopped unexpectedly ,麻烦各位看看这有什么问题?MP3的位置是这样吗?
来人呐######泪奔啊!!!! ListView listview=(ListView)findViewById(R.layout.list);!!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。