• listView 结合 ArrayList和HashMap 的应用


    music_item.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent"
    android:orientation
    ="horizontal"
    android:paddingLeft
    ="10dip"
    android:paddingRight
    ="10dip"
    android:paddingTop
    ="1dip"
    android:paddingBottom
    ="1dip">

    <TextView

    android:layout_width="wrap_content"
    android:layout_height
    ="wrap_content"
    android:id
    ="@+id/mp3_item"
    />
    <TextView android:id="@+id/mp3_name"
    android:layout_height
    ="30dip"
    android:layout_width
    ="fill_parent"
    android:textSize
    ="10pt"
    android:paddingLeft
    ="10dp"
    android:textColor
    ="#FFFFFF"/>
    </LinearLayout>

    列表

    /**
    * 文件过滤器
    *
    *
    @author
    *
    */
    class MusicFilter implements FilenameFilter {

    @Override
    public boolean accept(File dir, String filename) {

    return (filename.endsWith(".mp3"));
    }

    }

    //绑定音乐
    void musicList(){
    try{
    musiclist.clear();
    //扫描SD卡下MP3文件夹中的Mp3歌曲,将扫描出的MP3对象存放到集合中
    File mp3File=new File(SkyMusicActivity.SDPath);
    if(mp3File.listFiles(new MusicFilter()).length>=0){
    for(File file:mp3File.listFiles(new MusicFilter())){
    Mp3 mp3=new Mp3();
    String[] str=file.getName().split("\\.");
    mp3.setMp3_name(str[0]);
    mp3.setId(i);
    i++;
    musiclist.add(mp3);
    }
    }
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }

    @Override
    protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    HashMap<String, String> map=null;
    List<HashMap<String, String>> list=new ArrayList<HashMap<String,String>>();

    if(musiclist.size()!=0){
    for(Mp3 m:musiclist){
    map=new HashMap<String, String>();
    map.put("mp3_item", Integer.toString(m.getId()+1));
    map.put("mp3_name", m.getMp3_name());
    list.add(map);
    }
    SimpleAdapter adapter=new SimpleAdapter
    (this, list, R.layout.music_item, new String[]{"mp3_item","mp3_name"}, new int[]{R.id.mp3_item,R.id.mp3_name});
    setListAdapter(adapter);
    }
    }


    实现后的界面

  • 相关阅读:
    R镜像源的切换
    GWAS中的名称概念
    mac显示隐藏的文件,安装cocoapods
    swift开发笔记28 SlideBarMenu
    MAC读取安卓手机的APP的log日志
    关于DES加密中的 DESede/CBC/PKCS5Padding
    swift开发笔记27 UserNotifications
    swift开发笔记26 3D Touch
    银联Pos终端签到、签退、批结算、批上送、PinKey、MacKey、KEK、主密钥、工作密钥、TPDU、报文头
    开发感悟
  • 原文地址:https://www.cnblogs.com/shanshan520/p/2390541.html
Copyright © 2020-2023  润新知