2012-12-04 3 views
0

스페인어와 영어가 모두 표시되도록 앱을 현지화하려고합니다. 한 가지 예외를 제외하고 대부분의 현지화를 알아 냈습니다. 로캘을 추가하고 응용 프로그램을 번역 할 수 있도록 res/raw 폴더로 이동하려는 응용 프로그램에 대한 질문을 나열하는 .xml 파일이 있습니다.Android Asset to Raw

(getResources(). getString (R.string. "")을 사용하여 대부분의 문자열을/res에서 호출 할 수 있었기 때문에 대부분 쉽습니다. 그러나이 호출을 수행하는 데 어려움이 있습니다. 나의 현재의 인수.

I는 XML이 입술에있는 한/생/"."XML

와 나는 질문에 대한 .XML을 잡아 순간에 자산 관리자를 사용하고

public static List<Question> readQuestions(AssetManager assetManager){ 

    ArrayList<Question> questionArrayList = new ArrayList<Question>(); 
    try{ 
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder db = dbf.newDocumentBuilder(); 
     Document doc = db.parse(assetManager.open("questions.xml")); 
     doc.getDocumentElement().normalize(); 
     NodeList nodeLst = doc.getElementsByTagName("question"); 
     for(int s=0; s<nodeLst.getLength(); s++){ 

누구든지 .xml을 잡기 위해 원시 폴더를 호출 할 수있는 방법을 알고 있습니까?

편집 :::

내가의 InputStream에 대한 코드를 활용하려고 시도하고, 그러나 나는 말한다 심볼 '맥락'을 해결할 수없는 상황에서 오류가 발생

public static List<Question> readQuestions(AssetManager assetManager){ 

    ArrayList<Question> questionArrayList = new ArrayList<Question>(); 
    try{ 
     InputStream in = context.getResources().openRawResource(R.raw.questions); 
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder builder = factory.newDocumentBuilder(); 

     Document doc = builder.parse(in); 


     NodeList nodeLst = doc.getElementsByTagName("question"); 

답변

2

고해상도에 대한 InputStream를 얻으려면/raw/questions.xml

InputStream in = context.getResources().openRawResource(R.raw.questions); 

이 답변은 사용자가 컨텍스트를 가지고 있다고 가정합니다. 안드로이드에서 컨텍스트를 얻고 사용하는 것에 익숙하지 않다면, 정말로 그것을 이해하는 데 시간을 할애하는 것이 좋습니다. 그렇지 않으면 안드로이드 프로그래밍에서 멀지는 않을 것입니다.

StackOverflow에 대한 많은 답변이 이미 컨텍스트를 설명하고 있습니다. 여기있다 하나 What is 'Context' on Android?

+0

좋아, 미안 나는 꽤 안드로이드 프로그래밍에 신선한 오전, 당신은 내가 이것을 구현할 수있는 방법을 보여줄 수 있습니까? – WiseGuy

+0

문서 작성기를 던져야 할 것이라고 가정합니다 ... – WiseGuy

+0

사용 가능한 컨텍스트를 얻는 방법은 http://stackoverflow.com/questions/3572463/what-is-context-in-android를 참조하십시오. – slund