开发学院手机开发Android 开发 Android 快速实现一个文件选择器 阅读

Android 快速实现一个文件选择器

 2010-02-24 04:48:00 来源:WEB开发网   
核心提示:}}};ListFile(mCurrentDirectory);lv2.setOnItemClickListener(lv2click);}private void ListFile(File aDirectory) {ap.clearItems();ap.notifyDataSetChanged();lv2.post

}

}

};

ListFile(mCurrentDirectory);

lv2.setOnItemClickListener(lv2click);

}

private void ListFile(File aDirectory) {

ap.clearItems();

ap.notifyDataSetChanged();

lv2.postInvalidate();

Log.v("vodone","mpath="+aDirectory.getPath());

//if (aDirectory==null)return;

if (!aDirectory.getPath().equals("/sdcard")){

fileData fd=new fileData();

fd.name="..";

fd.type=1;

ap.addItem(fd);

}

for( File f : aDirectory.listFiles() ){

if (f.isDirectory()){

fileData fd=new fileData();

ffd.name=f.getName();

fd.type=1;

ap.addItem(fd);

}else{

if (checkEnds(f.getName().toLowerCase())){

fileData fd=new fileData();

ffd.name=f.getName();

fd.type=0;

ap.addItem(fd);

}

}

}

ap.notifyDataSetChanged();

lv2.postInvalidate();

}

private boolean checkEnds(String checkItsEnd) {

for (String aEnd : fileEndings) {

if (checkItsEnd.endsWith(aEnd))

return true;

}

return false;

}

}

public class frm_openfile extends Activity implements OnClickListener {

ListView lv2;

private File mCurrentDirectory = new File("/sdcard/");

ExpBaseAdapter ap;

String fileEndings[]={"png","bmp","jpg","jpeg","avi","3gp","mp3","mp4"};

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setTitle(R.string.text_selectfile);

setContentView(R.layout.frm_openfile);

lv2 = (ListView)findViewById(R.id.of_lv);

lv2.setCacheColorHint(0x00000000);

ap=new ExpBaseAdapter(this);

上一页  1 2 3 4 5  下一页

Tags:Android 快速 实现

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接