在网上找了一段读取txt文件的代码,但只能显示一屏内容,如何实现翻页,或向下滚动显示全部内容?以下是我的代码,请教如何修改:
------------------------------------------------------------------------
String fileName = "01.txt"; //文件名字 String res="";
private TextView myTextView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{ InputStream in = getResources().getAssets().open(fileName);
int length = in.available(); byte [] buffer = new byte[length]; in.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); }catch(Exception e){ e.printStackTrace(); }
myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setText(res);
}
------------------------------------------------------------------------
String fileName = "01.txt"; //文件名字 String res="";
private TextView myTextView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{ InputStream in = getResources().getAssets().open(fileName);
int length = in.available(); byte [] buffer = new byte[length]; in.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); }catch(Exception e){ e.printStackTrace(); }
myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setText(res);
}
in.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8"); 这段代码写在一个循环里,判断是否读到结尾,如果读到结尾就继续读..
修改layout中的textview属性,比如
android:scrollbars="vertical" <!--垂直滚动条 -->
android:singleLine="false" <!--实现多行 -->
android:maxLines="15" <!--最多不超过15行 -->