Java Android table 不显示

Java Android table not displayed

我编写了以下代码:

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

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

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