Android 动态添加GridView

Android 动态添加GridView,android,android-widget,Android,Android Widget,我想以表格的形式显示数据。但问题是活动上显示的表的数量将是动态的。假设数据库中有4个用户,我将显示4个表,每个表包含一个用户的数据 我已尝试通过编程方式将表添加到我的LinearLayout。但页面上绝对没有显示任何内容。以下是我在表中使用的代码: TableRow tr = new TableRow( this ); tr.setLayoutParams(newTableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,Tabl

我想以表格的形式显示数据。但问题是活动上显示的表的数量将是动态的。假设数据库中有4个用户,我将显示4个表,每个表包含一个用户的数据

我已尝试通过编程方式将表添加到我的LinearLayout。但页面上绝对没有显示任何内容。以下是我在表中使用的代码:

TableRow tr = new TableRow( this );
tr.setLayoutParams(newTableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));

/* Create a Button to be the row-content. */
Button b = new Button( this );
b.setText("Dynamic Button");
b.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));

/* Add Button to row. */
tr.addView(b);

/* Add row to TableLayout. */
TableLayout tl = new TableLayout(getActivity());
tl.addView(tr,new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));

LinearLayout linearLayout = (LinearLayout)getActivity().findViewById(R.id.RelativeLayout_schoolAssignments);
linearLayout.addView(tl);
我还考虑过使用GridView。但我找不到一种不使用GridviewAdapter,通过编程将行添加到网格的方法。 我在找这样的东西:

GridView gv = new GridView( this );
GridRow gr = /* Some code here */;

gv.addRow( gr );

linearLayout.addView( gv );

有这样一种简单的方法吗?

向gridview添加数据您必须而且应该使用任何适配器。@Pravena_Pinki您能帮我弄清楚为什么不动态添加到表中的行对我不可见吗?我做错什么了吗?