- How can I add extra TableRows to my TableLayout depending on cursor?
- TableLayout tl = (TableLayout)findViewById(R.id.table_layout2);
- TableRow tr = new TableRow(this);
- tr.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- TextView mTvDate = new TextView(this);
- TextView mTvResult = new TextView(this);
- int x=0;
- for(int i=0;i<c.getCount();i++){
- mTvDate.setText(date[x]);
- mTvResult.setText(""+nocorrect[x]+" av "+ noqs[x] +" ("+ proc[x]+ "%)");
- mTvDate.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- mTvResult.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- tr.addView(mTvDate);
- tr.addView(mTvResult);
- tl.addView(tr,new TableLayout.LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- }
- 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.
- TableLayout tl = (TableLayout)findViewById(R.id.table_layout2);
- int x=0;
- for(int i=0;i<c.getCount();i++){
- TableRow tr = new TableRow(this);
- tr.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- TextView mTvDate = new TextView(this);
- TextView mTvResult = new TextView(this);
- mTvDate.setText(date[x]);
- mTvResult.setText(""+nocorrect[x]+" av "+ noqs[x] +" ("+ proc[x]+ "%)");
- mTvDate.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- mTvResult.setLayoutParams(new LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- tr.addView(mTvDate);
- tr.addView(mTvResult);
- tl.addView(tr,new TableLayout.LayoutParams(
- LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
- }