2012-12-05 3 views
0

나는 웹에서 날짜를 텍스트 형식으로 가져 오는이 코드를 가지고 있습니다.

모든 줄마다 새 줄에 settext 출력을 얻으려면 어떻게해야합니까?

는 여기에 구글 스프레드 시트에 텍스트 파일이 내 코드

package com.zv.android; 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.MalformedURLException; 
import java.net.URL; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class ZipActivity extends Activity { 

    TextView textMsg, textPrompt; 
    final String textSource = "https://docs.google.com/spreadsheet/pub?key=0iojoI1OogsdiojdsiosdSdzZlbmZqOHdijoQkE&single=true&gid=0&range=A2%3AA200&output=txt"; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     textPrompt = (TextView)findViewById(R.id.textprompt); 
     textMsg = (TextView)findViewById(R.id.textmsg); 

     textPrompt.setText("Wait..."); 

     URL CPSE; 
     try { 
      CPSE = new URL(textSource); 
      BufferedReader bufferReader = new BufferedReader(new InputStreamReader(CPSE.openStream())); 
      String StringBuffer; 
      String stringText = ""; 
      while ((StringBuffer = bufferReader.readLine()) != null) { 
       stringText += StringBuffer; 
      } 
      bufferReader.close(); 
      textMsg.setText(stringText); 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      textMsg.setText(e.toString()); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      textMsg.setText(e.toString()); 
     } 

     textPrompt.setText("Finished!"); 

    } 
} 

입니다. 자동으로 업데이트됩니다.

안드로이드 응용 프로그램에 데이터를 가져올 수 있지만 스프레드 시트에있는 것처럼 줄 바꿈 대신 한 줄로 모두 출력합니다.

+2

stringText을 읽을; – dymmeh

+0

고마워 .... 너는 끝내 주네. 언젠가 자바를 완성하지 못했다. :) – Mowgli

+0

더 빨리 새로 고침하지 않아서 새 데이터로 새로 고침을 할 수있다. 집으로 돌아가서 앱을 닫는다. . – Mowgli

답변

1

추가] 개행 문자 \n 각 줄 끝에서 당신은 + = StringBuffer를 + "\ n"

while ((StringBuffer = bufferReader.readLine()) != null) { 
      stringText += StringBuffer + "\n"; 
} 
관련 문제