Android-用ListView显示SDCard文件列表

【转载】

本文简单实现了用ListView显示SDCard文件列表,目录的回退等功能暂不讨论

获取文件列表,files即为所选择目录下的所有文件列表:

filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ADASiteMaps/SigRecord";
        File file=new File(filePath);
        File[] files = file.listFiles();

构造Adapter,

        for(File mCurrentFile:files){
            mFileName.add(mCurrentFile.getName());
        }

        ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,mFileName);  

显示 ListView 
        fileListView.setAdapter(mAdapter);

 

ListView点击事件的处理:

        fileListView = (ListView) findViewById(R.id.filelistView); 
        fileListView.setOnItemClickListener(fileListViewItemClickListener);

    private AdapterView.OnItemClickListener fileListViewItemClickListener = 
        new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                // TODO Auto-generated method stub
                
                //test.........................
               // TextView textview = (TextView)findViewById(R.id.textViewfile);
               // textview.append(mFileName.get(position).toString());
            }        
    };

结果如下图:

 

转载本站文章请注明,转载自:ADASiteMap的空间[http://www.adasitemap.tk]

posted on 2013-11-27 16:47  MasonChi  阅读(199)  评论(0编辑  收藏  举报

导航