如何在包含资产文件夹 android studio 的列表视图中获取文本文件

how to get text file in listview containing in Assets folder android studio

如何在 Android Studio 中将资产文件夹文件名显示到回收站视图中?

我的 Assets 文件夹中的文件是 Apple.txt、Banana.json、cat.xml、Dog.xml、Elephant.java、Fox.json、Got.gradle等 我只想在列表中输入名称,例如 Apple.txt

您可以通过调用AssetManager提供的API来访问应用程序的原始资产文件。

AssetManager assetManager = context.getAssets();
String[] files = assetManager.list("");  // "" means asset root folder

在您获得包含根文件夹中所有资产的字符串数组后,您可以将该数组传递给您的 RecyclerView.Adapter 并将其绑定到 onBindViewHolder 中的 RecyclerView.ViewHolder

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