写列表视图内容的HTML文件的android [英] Writing listview contents to html file android

查看:173
本文介绍了写列表视图内容的HTML文件的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正从我的数据库填补了列表视图。现在,我想借此列表视图中的内容,并显示在HTML表。

I have a listview that is being filled from my database. Now I want to take the contents of this listview and show it in html table.

我怎样才能把我的ListView和它的内容写入HTML文件?

How I can take my listview and write its contents to html file?

推荐答案

我只是做了非常类似的东西在这里。

I just did something very similar here.

 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;
    }
}

我在写这是我后来附加到电子邮件或通过蓝牙发送,或让它在文件的文件。我的文件是CSV(比赛结果),并生成文件的名称。但是,你能适应供您使用。

I was writing to a file which I later attach to an email or send via BlueTooth, or just leave it on file. My file is CSV (race results) and the name of the file is generated. But you can adapt for your use.

这篇关于写列表视图内容的HTML文件的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆