Tanzil
Tanzil

Reputation: 111

how to use cursor.getString data for getResources()?

I know this code will open dummytext.txt file on res/raw

InputStream inputStream = getResources().openRawResource(
R.raw.dummytext);

But if filename dummytext is getting from search query like using this code-

int Index = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_DETAILS);
details.setText(cursor.getString(Index));

Then how could i open dummytext file via InputStream inputStream command?

Upvotes: 0

Views: 125

Answers (1)

wangyif2
wangyif2

Reputation: 2863

You can get the ResourceId by:

int dummyTextID = this.getResources().
    getIdentifier(cursor.getString(Index), "raw", getPackageName());

And then do:

InputStream inputStream = getResources().openRawResource(dummyTextID);

Upvotes: 1

Related Questions