当您点击按钮(简单应用)时,我需要构建一个显示textView的图书应用
问题是我在这个文本中有100,000个单词(来自资源文件夹) 装载是8秒!!在最新的Android手机
我正在阅读输入流和获取资产的文本
以高性能阅读此文本的选项是什么,或者我应该将文本拆分为多个小文件?
代码:
public String getString(String fileName) {
String text = "nothing";
AssetManager am = getAssets();
InputStream is = null;
try {
is = am.open(fileName);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int tav = is.read();
while (tav != -1) {
baos.write(tav);
tav = is.read();
}
text = baos.toString();
} catch (IOException e) {
text = e.getMessage();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
text = e.getMessage();
}
}
}
return text;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_rabi_nahman, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
感谢
答案 0 :(得分:0)
使用WebView而不是TextView。