2012-04-24 4 views
3

나는 잠시 동안 onine을 검색해 왔으며이 문제에 대한 올바른 대답을 찾을 수 없었습니다. 긴 이야기하자면, 나는받은 편지함으로 사용할 웹 페이지를 모으고 있습니다. 필자는 각 "메시지"사이에 줄을 건너 뛰고 필자가
태그를 내 PHP에 넣어야했습니다. 웹 브라우저에서 완벽하게 작동하지만 Android 애플리케이션에서는 실제로
태그를 일반 텍스트로 볼 수 있습니다. 그냥 "다음/새로운 라인"으로 그들을 읽으려고. 어떤 아이디어? 안드로이드에서 <br /> 태그를 처리하는 방법

내 메소드 코드 :

public String getInbox(String where){ 

     BufferedReader in = null; 
     String data = null; 
     try{ 


      HttpClient client = new DefaultHttpClient(); 
      URI website = new URI("http://example.com/getInbox.php?where="+where); 

      HttpPost post_request = new HttpPost(); 
      post_request.setURI(website); 


      HttpGet request = new HttpGet(); 

      request.setURI(website); 
      //executing actual request 

         //add your implementation here 
      HttpResponse response = client.execute(request); 

      in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
      StringBuffer sb = new StringBuffer(""); 
      String l = ""; 
      String nl = System.getProperty("line.separator"); 
      while ((l = in.readLine()) != null) { 
       sb.append(l+nl); 

      } 
      in.close(); 
      data = sb.toString(); 


return data; 
     }catch (Exception e){ 
      return "ERROR"; 

     } 

     } 

웹 페이지에서 출력 :

eg test 
eg test 
eg lol 
eg lol 
eg testing 

안드로이드의 출력 :

eg test<br />eg test<br />eg lol<br />eg lol<br />eg testing<br />eg 

답변

9
String lineSep = System.getProperty("line.separator"); 
String yourString= "test<br />eg test<br />eg lol<br />eg lol<br />eg testing<br />eg34 ernestggggg"; 


yourString= yourString.replaceAll("<br />", lineSep): 
+0

이것은 효과가 있었다. 정말 고마워. 이러한 쉬운 솔루션. 'replace'와'replaceAll'은 큰 차이가 있습니다. 다시 한 번 감사드립니다. – EGHDK

0

당신이에 html로 변환하는 Html.fromHtml()을 사용할 수 있습니다 Spanned이있는 문자열 Html 포함.

0

체크 아웃 당신이 당신의 웹 브라우저에서 보여로 텍스트를 표시합니다 새로운 라인 "\n"

data = sb.toString(); 

data = data.replaceAll("<br />", "\n"); 

return data; 
2

<br /> 태그를 교체합니다. 이를 위해 다음 방법을 사용해야합니다.

TextView tv = (TextView)findViewById(R.id.tv); 
tv.setText(Html.fromHtml( " Overs Alloted " + "<small> <small> " + "at start of innings" + "</small> </small>")); //Example 

String s= getStringFromSoruce(parameters); //Pass the string you need here 
tv.setText(Html.fromHtml(s)); 

모든보기를 사용하여 텍스트를 설정할 수 있습니다. 이것을 사용하여 더 많은 HTML 태그를 제거 할 수도 있습니다.

나는 이것이 당신의 목적을 해결했으면 좋겠다. :)

관련 문제