2012-12-05 2 views
0

나는 assetmanager를 사용하여 문자열에 의해 참조되는 xml 파일을 구문 분석하려고하는데, 나는 지금까지 가지고있는 덕분에 많은 도움을 받았습니다.안드로이드 AssetManager 문자열 파싱

Document doc = db.parse(assetManager.open(Resources.getSystem().getString(R.string.FileName))); 

문자열 파일 이름은 나는이 그래서 결국 나는 여러 XML 파일에 대한 내 응용 프로그램에 지역화를 적용 할 수 있습니다하고있어, 내 questions.xml 파일입니다. 그러나 내 응용 프로그램은 R.string.FileName을 읽을 수 없으며 응용 프로그램에서 오류가 발생합니다. 누구든지 나를 도울 수 있습니까?

+1

가 [localitzation] 할 (HTTP : //developer.android.com/guide/topics/resources/localization.html)? – zapl

+0

정상적인 방법을 사용하여 다른 모든 것을 현지화했지만 XML을 자산 내에 보관해야합니다. – WiseGuy

답변

4

Resources.getSystem()은 시스템 리소스 (android.R.x.x) 만 읽습니다. 코드는 Activity에있는 경우

는, 다음과 같은 사용 : 그렇지 않으면

String fname = getResources().getString(R.string.FileName); 
Document doc = db.parse(assetManager.open(fname)); 

을,이를 사용하면 일반 방법을 사용하지 않는 이유는

String fname = context.getResources().getString(R.string.FileName); // `context` is a Context object which you need to pass to this. 
Document doc = db.parse(assetManager.open(fname)); 
+0

굉장, 에릭에게 감사드립니다. 이것은 또한 컨텍스트 개체를 더 잘 이해할 수 있도록 도왔습니다. :) – WiseGuy