gpt4 book ai didi

java - 如何在每行换行中获取settext输出?

转载 作者:行者123 更新时间:2023-12-01 15:00:26 30 4
gpt4 key购买 nike

我有这段代码,它以文本格式从网络获取日期。

这是我的代码

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 应用程序,但它以单行形式输出所有内容,而不是像电子表格中那样以换行符形式输出。

最佳答案

在您阅读的每一行后面附加换行符 \n

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

关于java - 如何在每行换行中获取settext输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13731651/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com