我有一个从我的数据库中填充的列表视图。现在我想获取这个listview的内容并在html表中显示它。
如何获取listview并将其内容写入html文件?
答案 0 :(得分:1)
我在这里做了一些非常相似的事情。
private File saveResults() {
/*
* Write the results to a file.
*/
List<RiderResult> Results = DataModel.get().getResults();
try {
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
Toast.makeText(SummaryFragment.this.getContext(), "Unable to access external storage.",
Toast.LENGTH_SHORT).show();
return null;
}
/*
* Create a file folder in external storage.
*/
File csvDir = new File(
Environment.getExternalStorageDirectory(),
"Android/data/ca.mydomain.myapp/results");
if (!csvDir.exists())
csvDir.mkdirs();
/*
* Create a file in the folder, with today's date and time as the name.
*/
Date dateNow = new Date ();
SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMddHHmm");
StringBuilder nowMMDDYYYY = new StringBuilder( dateformatYYYYMMDD.format( dateNow ) );
File csvFile = new File(csvDir, "result_" + nowMMDDYYYY + ".csv");
BufferedWriter bw = new BufferedWriter(new FileWriter(csvFile, false));
/*
* Write a header row.
*/
bw.write("Finish Seq, Start Num,Clock Time, Actual Time\n");
/*
* and a row for each result, comma separated
*/
for (int i = 0; i < Results.size(); i++) {
String row = new String();
row = "" + (i + 1) + "," + Results.get(i).getStartNo()
+ "," + Results.get(i).getClockTimeString() + ","
+ Results.get(i).getActualTimeString() +"\n";
bw.write(row);
}
bw.close();
/*
* Return the File to the user - for use in a message or email attachment.
*/
return csvFile;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
我正在写一个文件,我后来将其附加到电子邮件或通过BlueTooth发送,或者只是将其存档。我的文件是CSV(竞赛结果),并生成文件名。但你可以适应你的使用。