【发布时间】:2014-03-21 04:53:24
【问题描述】:
我正在构建一个表格来显示数据库中的项目。我目前正在尝试启用滚动,以便所有列和行都可见,但它不起作用。该表未绑定到 xml 文件。这是生成表格的代码部分。
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();
}
任何帮助或建议将不胜感激。
【问题讨论】:
-
stackoverflow 问题stackoverflow.com/questions/16623337/…可能重复