How to read many file from raw resource in loop?

后端 未结 2 730
逝去的感伤
逝去的感伤 2021-01-06 13:28

I have many text files and want to put them in a for loop.

I get an Extra that have Resource name from last activity (s) and have an array that have Resource name of

2条回答
  •  攒了一身酷
    2021-01-06 13:41

    You can use getIdentifier (String name, String defType, String defPackage) for fetching resource id dynamically,

    ArrayList id = new ArrayList();
    for (int i = 0; i <= 79; i++) {
      id.add(getResources().getIdentifier("d"+i, "raw", getPackageName()));
    }
    

    Now you will have all the resources id's inside id ArrayList

提交回复
热议问题