How to read many file from raw resource in loop?

后端 未结 2 748
逝去的感伤
逝去的感伤 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:55

    I have 6 variations of resources in one place I need to read.

        try
         {
            for (int i = 0; i < 6; i++ )
             {
                  String fname = "p" + i;
                  int id = context.getResources().getIdentifier(fname, "drawable", "com.example.yourproject");
                  if (id == 0)
                  {
                      Log.e(TAG, "Lookup id for resource '"+fname+"' failed");
                      // graceful error handling code here
                  }
                 scoresBm[i] =  (Bitmap) BitmapFactory.decodeResource(context.getResources(), id);
             }
        }
        catch(Exception E)
        {
        }
    

提交回复
热议问题