1
 InputStream inputStream = getResources().openRawResource(R.raw.ac);

ここで、ac は res/raw からの定数ファイル名です。

int books = cursor.getColumnIndexOrThrow(DictionaryDatabase.BOOK_DETAILS)

int には name: ac も含まれます。

使用することは可能ですか

InputStream inputStream = getResources().openRawResource( Int ブック); ???

はいの場合、どのように??

4

1 に答える 1

1

私の理解が正しければ、変数R.raw.xxxxに名前を持つフィールドの値を取得したいと考えています。xxxxこれは、次のようなコードで実現できます。

String resName = "mybook";
int resID = context.getResources().getIdentifier(resName, "raw", context.getPackageName());
InputStream inputStream = getResources().openRawResource(resId);

contextこれは、アプリ内の のインスタンスでありContext、アクティビティ内では、これは になりますthis

于 2013-04-26T13:16:35.123 に答える