I got an editText which allow the user to type the file name, but since all the files are in the raw folder. I tried to get the file from the raw folder and here is the problem,
String fileName = editText.getText().toString;
InputStream ins = getResources().openRawResource(R.raw.my_db_file);
how can I replace “my_db_file” to fileName? it seems not allow me to code it like this
InputStream ins = getResources().openRawResource(R.raw.fileName);
any idea? thanks so much for the help
Use
getResources().getIdentifier()to convert aStringrepresenting a resource name into a resource ID. Note that this uses reflection under the covers, so please cache your result.