如何将mp3文件以列表的形式显示出来?

本文介绍了一个简单的Android应用程序中实现列表视图更新的方法。通过下载XML文件并解析其中的MP3信息,然后使用SimpleAdapter适配器来显示这些信息。文章还展示了如何处理菜单项点击事件,特别是更新列表和关于选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == UPDATE) { updateListView(); } else if (item.getItemId() == ABOUT) { // 用户点击了关于按钮 } return super.onOptionsItemSelected(item); } private SimpleAdapter buildSimpleAdapter(List<Mp3Info> mp3Infos){ // 生成一个List对象,并按照SimpleAdapter的标准,将mp3Infos当中的数据添加到List当中去 List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); for (Iterator iterator = mp3Infos.iterator(); iterator.hasNext();) { Mp3Info mp3Info = (Mp3Info) iterator.next(); HashMap<String, String> map = new HashMap<String, String>(); map.put("mp3_name", mp3Info.getMp3Name()); map.put("mp3_size", mp3Info.getMp3Size()); list.add(map); } // 创建一个SimpleAdapter对象 SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.mp3info_item, new String[] { "mp3_name", "mp3_size" }, new int[] { R.id.mp3_name, R.id.mp3_size }); // 将这个SimpleAdapter对象设置到ListActivity当中 return simpleAdapter; } private void updateListView() { // 用户点击了更新列表按钮 // 下载包含所有Mp3基本信息的xml文件 String xml = downloadXML("http://219.245.78.236:8080/mp3/resources.xml"); // 对xml文件进行解析,并将解析的结果放置到Mp3Info对象当中,最后将这些Mp3Info对象放置到List当中 List<Mp3Info> mp3Infos = parse(xml); SimpleAdapter simpleAdapter = buildSimpleAdapter(mp3Infos); setListAdapter(simpleAdapter); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值