0

ファイル名をres/valuesから文字列として参照することにより、アセットにあるxmlファイルを解析することは可能ですか?

 Document doc = db.parse(assetManager.open("questions.xml"));

そして、questions.xmlの代わりに@ string / questions.xmlのようなものですか?これを機能させるのに苦労しています。

4

1 に答える 1

2

あなたはこのコードでそれを行うことができます:

Resources res = getApplicationContext().getResources();
String filename = res.getString(R.string.questions);
Document doc = db.parse(assetManager.open(filename));

または1つの簡単な行で:

Document doc = db.parse(assetManager.open(getApplicationContext().getResources().getString(R.string.questions));

お役に立てば幸いです。

于 2012-12-05T15:30:32.970 に答える