I am building a table to display items from a database. I am currently trying to enable scrolling so that all columns and rows are visible but it's not working. The table is not tied to an xml file. This is the portion of the code that generates the table.
public void showdata(View view)
{
Cursor c=db.rawQuery("SELECT * from Student", null);
int count= c.getCount();
c.moveToFirst();
TableLayout tableLayout = new TableLayout(getApplicationContext());
tableLayout.setVerticalScrollBarEnabled(true);
tableLayout.setHorizontalScrollBarEnabled(true);
TableRow tableRow;
TextView textView,textView1,textView2,textView3,textView4,textView5,textView6,textView7;
tableRow = new TableRow(getApplicationContext());
textView=new TextView(getApplicationContext());
textView.setText("Module Code");
textView.setTextColor(Color.RED);
textView.setTypeface(null, Typeface.BOLD);
textView.setPadding(20, 20, 20, 20);
tableRow.addView(textView);
textView4=new TextView(getApplicationContext());
textView4.setText("Assignment Name");
textView4.setTextColor(Color.RED);
textView4.setTypeface(null, Typeface.BOLD);
textView4.setPadding(20, 20, 20, 20);
tableRow.addView(textView4);
textView5=new TextView(getApplicationContext());
textView5.setText("Marks Proportions");
textView5.setTextColor(Color.RED);
textView5.setTypeface(null, Typeface.BOLD);
textView5.setPadding(20, 20, 20, 20);
tableRow.addView(textView5);
textView6=new TextView(getApplicationContext());
textView6.setText("Due Date");
textView6.setTextColor(Color.RED);
textView6.setTypeface(null, Typeface.BOLD);
textView6.setPadding(20, 20, 20, 20);
tableRow.addView(textView6);
tableLayout.addView(tableRow);
for (Integer j = 0; j < count; j++)
{
tableRow = new TableRow(getApplicationContext());
textView1 = new TextView(getApplicationContext());
textView1.setText(c.getString(c.getColumnIndex("moduleCode")));
textView2 = new TextView(getApplicationContext());
textView2.setText(c.getString(c.getColumnIndex("assignmentName")));
textView3 = new TextView(getApplicationContext());
textView3.setText(c.getString(c.getColumnIndex("marksProportion")));
textView7 = new TextView(getApplicationContext());
textView7.setText(c.getString(c.getColumnIndex("dueDate")));
textView1.setPadding(20, 20, 20, 20);
textView2.setPadding(20, 20, 20, 20);
textView3.setPadding(20, 20, 20, 20);
textView7.setPadding(20, 20, 20, 20);
tableRow.addView(textView1);
tableRow.addView(textView2);
tableRow.addView(textView3);
tableRow.addView(textView7);
tableLayout.addView(tableRow);
c.moveToNext() ;
}
setContentView(tableLayout);
db.close();
}
any help or suggestions would be very much appreciated.