首页 > 系统 > Android > 正文

Android用ListView显示SDCard文件列表的小例子

2020-04-11 11:59:39
字体:
来源:转载
供稿:网友

复制代码 代码如下:

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());
            }       
    };


结果如下图:

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表