Search code examples
javaandroidandroid-recyclerviewassets

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


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


Solution

  • 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.