Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 2.35 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I add extra TableRows to my TableLayout depending on cursor?
  2. TableLayout tl = (TableLayout)findViewById(R.id.table_layout2);
  3.      TableRow tr = new TableRow(this);
  4.      tr.setLayoutParams(new LayoutParams(
  5.                              LayoutParams.FILL_PARENT,
  6.                              LayoutParams.WRAP_CONTENT));
  7.              TextView mTvDate = new TextView(this);
  8.              TextView mTvResult = new TextView(this);
  9.              int x=0;
  10.              for(int i=0;i<c.getCount();i++){
  11.              mTvDate.setText(date[x]);
  12.              mTvResult.setText(""+nocorrect[x]+" av "+ noqs[x] +" ("+ proc[x]+ "%)");
  13.              mTvDate.setLayoutParams(new LayoutParams(
  14.                              LayoutParams.FILL_PARENT,
  15.                              LayoutParams.WRAP_CONTENT));
  16.  
  17.              mTvResult.setLayoutParams(new LayoutParams(
  18.                              LayoutParams.FILL_PARENT,
  19.                              LayoutParams.WRAP_CONTENT));
  20.              tr.addView(mTvDate);
  21.              tr.addView(mTvResult);
  22.      tl.addView(tr,new TableLayout.LayoutParams(
  23.             LayoutParams.FILL_PARENT,
  24.              LayoutParams.WRAP_CONTENT));
  25.              }
  26.        
  27. 02-22 09:22:17.543: ERROR/AndroidRuntime(333): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  28.        
  29. TableLayout tl = (TableLayout)findViewById(R.id.table_layout2);
  30.  
  31.          int x=0;
  32.          for(int i=0;i<c.getCount();i++){
  33.  TableRow tr = new TableRow(this);
  34.  tr.setLayoutParams(new LayoutParams(
  35.                          LayoutParams.FILL_PARENT,
  36.                          LayoutParams.WRAP_CONTENT));
  37.          TextView mTvDate = new TextView(this);
  38.          TextView mTvResult = new TextView(this);
  39.          mTvDate.setText(date[x]);
  40.          mTvResult.setText(""+nocorrect[x]+" av "+ noqs[x] +" ("+ proc[x]+ "%)");
  41.          mTvDate.setLayoutParams(new LayoutParams(
  42.                          LayoutParams.FILL_PARENT,
  43.                          LayoutParams.WRAP_CONTENT));
  44.  
  45.          mTvResult.setLayoutParams(new LayoutParams(
  46.                          LayoutParams.FILL_PARENT,
  47.                          LayoutParams.WRAP_CONTENT));
  48.          tr.addView(mTvDate);
  49.          tr.addView(mTvResult);
  50.  tl.addView(tr,new TableLayout.LayoutParams(
  51.         LayoutParams.FILL_PARENT,
  52.          LayoutParams.WRAP_CONTENT));
  53.          }