I want to show data in tabular form. But the problem is that the number of tables shown on the activity will be dynamic. Lets say there are 4 users in database, I'll be showing 4 tables each one containing data of one user.
I have tried to programmatically add table to my LinearLayout. But absolutely nothing is shown on the page. Here is the code that I am using for table:
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);
I also considered using GridView. But I couldn't find out a way of programatically adding row to the grid without using GridviewAdapter. I am looking for somthing like this:
GridView gv = new GridView( this );
GridRow gr = /* Some code here */;
gv.addRow( gr );
linearLayout.addView( gv );
Does such a simple way exist?