
我在Android项目的“assets”文件夹中有一些带有HTML文件的文件夹.我需要从列表中的资产子文件夹中显示这些HTML文件.我已经写了一些关于制作这个列表的代码.
lv1 = (ListVIEw) findVIEwByID(R.ID.ListVIEw);// Insert array in ListVIEw// In the next row I need to insert an array of strings of file names// so please, tell me, how to get this arraylv1.setAdapter(new ArrayAdapter<String>(this, androID.R.layout.simple_List_item_1, filel));lv1.setTextFilterEnabled(true);// onclick items in ListVIEw:lv1.setonItemClickListener(new OnItemClickListener() { public voID onItemClick(AdapterVIEw<?> a, VIEw v, int position, long ID) { //Clicked item position String itemname = new Integer(position).toString(); Intent intent = new Intent(); intent.setClass(DrugList.this, Web.class); Bundle b = new Bundle(); //I don't kNow what it's doing here b.putString("defStrID", itemname); intent.putExtras(b); //start Intent startActivity(intent); }});解决方法:
private boolean ListAssetfiles(String path) { String [] List; try { List = getAssets().List(path); if (List.length > 0) { // This is a folder for (String file : List) { if (!ListAssetfiles(path + "/" + file)) return false; else { // This is a file // Todo: add file name to an array List } } } } catch (IOException e) { return false; } return true; } 使用资产文件夹的根文件夹名称调用ListAssetfiles.
ListAssetfiles("root_folder_name_in_assets");如果根文件夹是资产文件夹,则调用它
ListAssetfiles(""); 总结 以上是内存溢出为你收集整理的android – assets文件夹及其子文件夹中的文件列表全部内容,希望文章能够帮你解决android – assets文件夹及其子文件夹中的文件列表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)