英文:
how to get text file in listview containing in Assets folder android studio
问题
如何在Android Studio中将Assets文件夹中的文件名显示在RecyclerView中?
我的Assets文件夹中有Apple.txt、Banana.json、cat.xml、Dog.xml、Elephant.java、Fox.json、Got.gradle等文件。
我只想在列表中显示名称和类型,例如Apple.txt。
英文:
How to show assets folder file names into recycler view in Android Studio?
Files in my Assets folder are Apple.txt, Banana.json, cat.xml, Dog.xml, Elephant.java, Fox.json, Got.gradle etc
i want only name with it's type in list like Apple.txt
答案1
得分: 0
你可以通过调用AssetManager
提供的API来访问应用程序的原始资源文件。
AssetManager assetManager = context.getAssets();
String[] files = assetManager.list(""); // ""代表资源根文件夹
在获取包含根文件夹内所有资源的字符串数组后,你可以将该数组传递给你的RecyclerView.Adapter
,并在onBindViewHolder
中将其绑定到你的RecyclerView.ViewHolder
上。
英文:
You can access the application's raw asset files by calling APIs provided by AssetManager
.
AssetManager assetManager = context.getAssets();
String[] files = assetManager.list(""); // "" means asset root folder
After you get the String array that contains all the assets at the root folder, you can pass the array to your RecyclerView.Adapter
and bind it to your RecyclerView.ViewHolder
in onBindViewHolder
.
答案2
得分: 0
AssetManager assetManager = getApplicationContext().getAssets();
String[] files = new String[0]; // "" means asset root folder
try {
files = assetManager.list("activity");
} catch (IOException e) {
e.printStackTrace();
}
RecyclerView.Adapter adapter = new cvRecyclerAdapter(this, Arrays.asList(files));
chipsText.setAdapter(adapter);
英文:
AssetManager assetManager = getApplicationContext().getAssets();
String[] files = new String[0]; // "" means asset root folder
try {
files = assetManager.list("activity");
} catch (IOException e) {
e.printStackTrace();
}
RecyclerView.Adapter adapter = new cvRecyclerAdapter(this, Arrays.asList(files));
chipsText.setAdapter(adapter);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论