我是android开发的新手,并且遇到一个问题,我需要使用TextView
在WebView
中使用HTML表,并且还做了,但是我不解释为什么在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());
}
}
这是我到目前为止所做的。谢谢。