java - 在 Textview 中使用 HTML 标签形成一个从外部文件读取数据的表格
问题描述
我是 android 开发的新手,遇到了一个问题,我需要在TextView
using中使用 HTML 表WebView
并且也已经这样做了,但我不知道为什么在 Webview 中它只显示文件夹的最后一个文件。
这是我的 XML 文件:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/buttons"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wallpapere"
android:textColor="#ffff"
android:textSize="10dp"
tools:layout_editor_absoluteX="20dp"
tools:layout_editor_absoluteY="26dp" />
</LinearLayout>
</ScrollView>
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="136dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="73dp"
android:layout_alignParentLeft="true" />
这是我的主文件:
(File f : filesContent) {
if (f.isFile() && f.getPath().endsWith(".txt")) try {
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
int index;
String l1 = null,l2=null,l3=null,l4=null,l5=null;
br.readLine();
while ((line = br.readLine()) != null) {
if (line.contains("INITIATIVE")) {
index = 12;
l1 = line.substring(index, line.length());
} else if (line.contains("DETAILS")) {
index = 9;
l2 = line.substring(index, line.length());
} else if (line.contains("MAN HOUR")) {
index = 10;
l3 = line.substring(index, line.length());
} else if (line.contains("AMOUNT")) {
index = 8;
l4 = line.substring(index, line.length());
} else if (line.contains("NAME")) {
index = 6;
l5 = line.substring(index, 13);
line.substring(index, 13));
}
mhtml = "<html>" + "<table>" + "<table border=1>" + "<tr>" + "<td>" + l1 + "</td>" + "<td>" + l2 + "</td>" + "<td>" + l3 + "</td>" + "<td>" + l4 + "</td>" +"<td>" + l5 + "</td>" + "</tr>" + "</table></html>";
}
br.close();
webView.loadDataWithBaseURL(null,mhtml,"text/html","utf-8",null);
webView.loadData(mhtml.toString(), "text/html", "UTF-8");
} catch (IOException e) {
Log.d("Exception", e.toString());
}
}
这是我到目前为止所做的。谢谢。
解决方案
推荐阅读
- html - 关于 CSS GRID“悬停”下拉菜单的一个小问题
- javascript - 如何使用cheerio遍历嵌套的'div'元素
- oracle-apex - Oracle Apex,apex_app_builder_api 包的文档,或在交互式报告中动态设置 null
- php - 如何防止 Mamp phpMyadmin 中的格式参数不正确?
- javascript - 图像未以 react-native 显示,但所有其他数据都显示
- c++ - C++:我有两个数组,其中第一个和最后一个元素具有相同的内存地址
- sql - 原始查询不接受带日期的 where 条件
- firebase - 如何修复在颤振应用程序的 dart 文件中导入 firebase auth 后出现的 firebase 错误?
- postgresql - 第二次触发结果消失
- pip - 为什么执行“pip3 缓存清除”时出错?