我需要这个反向运行,以便线条以与此相反的顺序出现。有没有快速翻转TextView或类似的东西?谢谢你的帮助。如何从最后一行读取文本文件到第一个
try {
// Create a URL for the desired page
URL url = new URL("text.txt");
// Read all the text returned by the server
BufferedReader MyBr = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
line = MyBr.readLine();
TextView textview1 = (TextView) findViewById(R.id.textView1);
StringBuilder total = new StringBuilder();
while ((line = MyBr.readLine()) != null) {
total.append(line + "\r\n");}
textview1.setText(total);
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/wonderfull.ttf");
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setTypeface(tf);
MyBr.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
我是一个总noob。不知道UI线程是什么,我不害怕ANR,但是你的建议让我过去了我的问题。谢谢! – user974030
您的活动(及其调用的任何代码)中的代码在应用程序的主/ UI线程上执行。如果你做了一些需要很长时间(> 100ms)的事情,那么你的应用程序似乎会暂停并冻结给用户。如果他们尝试滚动或点击按钮,应用程序将不会响应。用户不喜欢那样。如果您将UI线程绑定超过5秒钟,则Android OS会向用户显示一个对话框,指出“Foo Application is Not Responding”。这是一个ANR。它会让用户选择终止你的应用程序。 – michaelg
你不希望发生这种情况。因此产生一个新的线程来完成像从网络上读取文件这样的长时间任务。你可以使用一个好的'ol java.lang.Thread',或者你可以使用android goodness像android.os.AsyncTask。阅读SDK文档中的这些类。 如果我的答案有帮助,那么请接受它。 – michaelg