Java Android表未显示

时间:2015-01-31 15:30:39

标签: java android android-tablelayout

我制作了以下代码:

TableLayout tableLayout = (TableLayout) tmpView.findViewById(R.id.tableLayout);
    TableRow tableRow;
    TableLayout.LayoutParams lp = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
    for (int i = 0; i < modules.length(); i++) {
        tableRow = new TableRow(this.getActivity());
        tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
        TextView title = null;
        TextView grade = null;
        try {
            title = new TextView(this.getActivity());
            title.setText(modules.getJSONObject(i).getString("title"));
            grade = new TextView(this.getActivity());
            grade.setText(modules.getJSONObject(i).getString("grade"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        tableRow.addView(title);
        tableRow.addView(grade);
        tableLayout.addView(tableRow, lp);
}

但屏幕上没有显示任何内容 你知道它为什么不起作用吗?

1 个答案:

答案 0 :(得分:0)

找到解决方案,TableLayout动态声明然后在视图上设置