AssetManager am=getAssets();
try {
files = am.list("music");
Log.d("++++++++++++length++++++++++",""+files.length);
if (files == null) {
// dir does not exist or is not a directory
Toast.makeText(getApplicationContext(), "Directory not exist", Toast.LENGTH_SHORT).show();
} else {
for(String name : files){
Log.d("==========loop====",""+name);
此代码显示了logcat中存在的文件列表,但是当我使用arraylist添加它并为listview设置适配器时它没有显示任何内容......
答案 0 :(得分:-1)
AssetManager m=getAssets();
String files m.list(path);
Arraylist<yourmodelclassname> listviewadd=new Arraylist();
if (files == null) {
// dir does not exist or is not a directory
Toast.makeText(getApplicationContext(), "Directory not exist", Toast.LENGTH_SHORT).show();
} else {
for(String name : files){
listviewadd.addall(name); //it will added your adapter class and then set your listview.
}
directly access assets folder in this way to use..
i used to access font.
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/ARIAL.TTF");