Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从字符串数组创建表_Java_Android_Arrays - Fatal编程技术网

Java 从字符串数组创建表

Java 从字符串数组创建表,java,android,arrays,Java,Android,Arrays,我有一个字符串数组: String[] arr = { "04:20", "05:25", "05:41", "05:57", "06:13", "06:29", "06:37", "06:45", "06:53", "07:01", "07:09", "07:17", "07:25", "07:33", "07:41", "07:49", "07:57", "08:05",

我有一个
字符串
数组:

String[] arr = {
            "04:20",
            "05:25", "05:41", "05:57",
            "06:13", "06:29", "06:37", "06:45", "06:53",
            "07:01", "07:09", "07:17", "07:25", "07:33", "07:41", "07:49", "07:57",
            "08:05", "08:13", "08:21", "08:29", "08:37", "08:45", "08:53"
    };
我想从这个字符串数组创建

实现这一点的更好方法是什么?我在考虑
TableLayout
HTML
我不知道什么更好

问题:如何从字符串数组动态创建表

我的代码:

 String tempHours = "00:";
    ArrayList<Items> items_data = new ArrayList<>();
    for(String s: arr){
        String[] split = s.split(":");
        String hours = split[0] + ":";
        if(tempHours.equals(hours)) {
            items_data.add(new Items(split[0], split[1]));
        } else {
            tempHours = hours;
            items_data.add(new Items("\n" + split[0],split[1]));
        }
    }

    TableLayout tl = new TableLayout(this);

    for (Items items : items_data) {
        TableRow tr = new TableRow(this);

        TextView hours = new TextView(this);
        hours.setText(items.getHours());
        tr.addView(hours);

        TextView minutes = new TextView(this);
        minutes.setText(items.getMinutes());
        tr.addView(minutes);


        tl.addView(tr);
    }

如果你个人觉得你的问题太广泛。
public class Items {

String hours;
String minutes;

public Items(String hours, String minutes) {
    this.minutes = minutes;
    this.hours = hours;
}

public String getMinutes() { return minutes; }
public String getHours() { return hours; }

}