2014-04-30 4 views
0

내 앱의 모든 새로운 버전에서 기본적으로 길이가 긴 (-ish) 텍스트 인 새로운 기능 섹션을 넣는 것을 좋아합니다. 아포스트로피와 백분율 기호 및 개행 문자가 많은 경향이 있습니다. 당신.긴 텍스트 문자열을 textviews에 넣기

모든 문제가있는 문자를 이스케이프 처리하고 개행 문자를 \n 또는 <br />으로 바꾸는 것 외에 텍스트보기에서로드하는 더 쉬운 방법이 있습니까?

답변

0

resource folderRaw 텍스트 파일로 텍스트를 저장하고

InputStream inputStream = getResources().openRawResource(R.raw.share); 
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 
    String line; 
    StringBuilder text = new StringBuilder(); 

    try { 
     while ((line = reader.readLine()) != null) { 
      text.append(line); 
      text.append('\n'); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

을 읽어 그리고 TextView

textView.setText(text.toString()); 
로 설정하지 마십시오