0

ウェブから日付をテキスト形式で取得するこのコードがあります。

これが私のコードです

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!");

    }
}

Google スプレッドシートにテキスト ファイルがあります。自動的に更新されます。

Androidアプリケーションにデータをフェッチすることはできますが、スプレッドシートのようにすべてを改行ではなく1行で出力します。

4

1 に答える 1

1

\n読むすべての行の後に改行文字を追加する

 while ((StringBuffer = bufferReader.readLine()) != null) {
            stringText += StringBuffer + "\n";
 }
于 2012-12-05T20:27:35.370 に答える