有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在包含资产文件夹安卓 studio的listview中获取文本文件

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

“我的资产”文件夹中的文件是Apple。香蕉。json,猫。xml,狗。xml,大象。爪哇,福克斯。json,明白了。格拉德尔等 我只想要一个名字和它的类型在列表中像苹果。文本


共 (2) 个答案

  1. # 1 楼答案

    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);
    
  2. # 2 楼答案

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

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

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