Add next row dynamically after third column
up vote
0
down vote
favorite
this is desired table layout:
+++++++++++++
+ + + +
+ 1 + 2 + 3 +
+ + + +
+++++++++++++
+ + + +
+ 4 + 5 + 6 +
+ + + +
+++++++++++++
+ + + +
+ 7 + 8 + - +
+ + + +
+++++++++++++
My table is dynamically created based on json data:
TableLayout tl = (TableLayout) findViewById(R.id.table);
JSONArray jsonArray = new JSONArray( all_gpio_json );
for ( i = 0; i < jsonArray.length(); i++)
...some dynamic table generation code like this:
TableRow row = new TableRow(this);
Switch sw = new Switch( this );
row.addView(sw);
tl.addView( row );
There is no problem to have table generated so, that each json value is represented by unique row, however i'd like to have layout that will have maximum 3 columns per row, and number of rows will be dynamically growing as long as there are json data in the loop.
I tried to add new row after existing row has 3 items filled already:
if (i % 3 == 1) TableRow new_row = new TableRow( this );
But im getting an error when new_row is supposed to be added:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.comain.tests, PID: 15519
java.lang.RuntimeException: Unable to start activity ComponentInfocom.comainxxx.tests/com.comainxxx.tests.MainActivity: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Anyone would have an idea how to achieve this to add new row on the fly?
EDIT: Solved by implementing grid view, that is more suitable for this task.
android
add a comment |
up vote
0
down vote
favorite
this is desired table layout:
+++++++++++++
+ + + +
+ 1 + 2 + 3 +
+ + + +
+++++++++++++
+ + + +
+ 4 + 5 + 6 +
+ + + +
+++++++++++++
+ + + +
+ 7 + 8 + - +
+ + + +
+++++++++++++
My table is dynamically created based on json data:
TableLayout tl = (TableLayout) findViewById(R.id.table);
JSONArray jsonArray = new JSONArray( all_gpio_json );
for ( i = 0; i < jsonArray.length(); i++)
...some dynamic table generation code like this:
TableRow row = new TableRow(this);
Switch sw = new Switch( this );
row.addView(sw);
tl.addView( row );
There is no problem to have table generated so, that each json value is represented by unique row, however i'd like to have layout that will have maximum 3 columns per row, and number of rows will be dynamically growing as long as there are json data in the loop.
I tried to add new row after existing row has 3 items filled already:
if (i % 3 == 1) TableRow new_row = new TableRow( this );
But im getting an error when new_row is supposed to be added:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.comain.tests, PID: 15519
java.lang.RuntimeException: Unable to start activity ComponentInfocom.comainxxx.tests/com.comainxxx.tests.MainActivity: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Anyone would have an idea how to achieve this to add new row on the fly?
EDIT: Solved by implementing grid view, that is more suitable for this task.
android
what is mean exactly about this sentence of u ??? (But this is not possible in java i guess)
– hamid keyhani
Nov 10 at 6:42
i updated my question adding the error code
– B.Ondrej
Nov 10 at 6:58
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
this is desired table layout:
+++++++++++++
+ + + +
+ 1 + 2 + 3 +
+ + + +
+++++++++++++
+ + + +
+ 4 + 5 + 6 +
+ + + +
+++++++++++++
+ + + +
+ 7 + 8 + - +
+ + + +
+++++++++++++
My table is dynamically created based on json data:
TableLayout tl = (TableLayout) findViewById(R.id.table);
JSONArray jsonArray = new JSONArray( all_gpio_json );
for ( i = 0; i < jsonArray.length(); i++)
...some dynamic table generation code like this:
TableRow row = new TableRow(this);
Switch sw = new Switch( this );
row.addView(sw);
tl.addView( row );
There is no problem to have table generated so, that each json value is represented by unique row, however i'd like to have layout that will have maximum 3 columns per row, and number of rows will be dynamically growing as long as there are json data in the loop.
I tried to add new row after existing row has 3 items filled already:
if (i % 3 == 1) TableRow new_row = new TableRow( this );
But im getting an error when new_row is supposed to be added:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.comain.tests, PID: 15519
java.lang.RuntimeException: Unable to start activity ComponentInfocom.comainxxx.tests/com.comainxxx.tests.MainActivity: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Anyone would have an idea how to achieve this to add new row on the fly?
EDIT: Solved by implementing grid view, that is more suitable for this task.
android
this is desired table layout:
+++++++++++++
+ + + +
+ 1 + 2 + 3 +
+ + + +
+++++++++++++
+ + + +
+ 4 + 5 + 6 +
+ + + +
+++++++++++++
+ + + +
+ 7 + 8 + - +
+ + + +
+++++++++++++
My table is dynamically created based on json data:
TableLayout tl = (TableLayout) findViewById(R.id.table);
JSONArray jsonArray = new JSONArray( all_gpio_json );
for ( i = 0; i < jsonArray.length(); i++)
...some dynamic table generation code like this:
TableRow row = new TableRow(this);
Switch sw = new Switch( this );
row.addView(sw);
tl.addView( row );
There is no problem to have table generated so, that each json value is represented by unique row, however i'd like to have layout that will have maximum 3 columns per row, and number of rows will be dynamically growing as long as there are json data in the loop.
I tried to add new row after existing row has 3 items filled already:
if (i % 3 == 1) TableRow new_row = new TableRow( this );
But im getting an error when new_row is supposed to be added:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.comain.tests, PID: 15519
java.lang.RuntimeException: Unable to start activity ComponentInfocom.comainxxx.tests/com.comainxxx.tests.MainActivity: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Anyone would have an idea how to achieve this to add new row on the fly?
EDIT: Solved by implementing grid view, that is more suitable for this task.
android
android
edited Nov 12 at 7:40
asked Nov 9 at 21:58
B.Ondrej
589
589
what is mean exactly about this sentence of u ??? (But this is not possible in java i guess)
– hamid keyhani
Nov 10 at 6:42
i updated my question adding the error code
– B.Ondrej
Nov 10 at 6:58
add a comment |
what is mean exactly about this sentence of u ??? (But this is not possible in java i guess)
– hamid keyhani
Nov 10 at 6:42
i updated my question adding the error code
– B.Ondrej
Nov 10 at 6:58
what is mean exactly about this sentence of u ??? (But this is not possible in java i guess)
– hamid keyhani
Nov 10 at 6:42
what is mean exactly about this sentence of u ??? (But this is not possible in java i guess)
– hamid keyhani
Nov 10 at 6:42
i updated my question adding the error code
– B.Ondrej
Nov 10 at 6:58
i updated my question adding the error code
– B.Ondrej
Nov 10 at 6:58
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
It is possible in java. U need to declare that variable outside the if condition. Try below code
TableRow new_row = new TableRow(this);
for ( i = 0; i < jsonArray.length(); i++)
if (i % 3 == 0 && i != 0) new_row = new TableRow( this );
.......
Switch sw = new Switch( this );
new_row .addView(sw);
add a comment |
up vote
0
down vote
EDIT: Solved by implementing grid view, that is more suitable for this task.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It is possible in java. U need to declare that variable outside the if condition. Try below code
TableRow new_row = new TableRow(this);
for ( i = 0; i < jsonArray.length(); i++)
if (i % 3 == 0 && i != 0) new_row = new TableRow( this );
.......
Switch sw = new Switch( this );
new_row .addView(sw);
add a comment |
up vote
0
down vote
It is possible in java. U need to declare that variable outside the if condition. Try below code
TableRow new_row = new TableRow(this);
for ( i = 0; i < jsonArray.length(); i++)
if (i % 3 == 0 && i != 0) new_row = new TableRow( this );
.......
Switch sw = new Switch( this );
new_row .addView(sw);
add a comment |
up vote
0
down vote
up vote
0
down vote
It is possible in java. U need to declare that variable outside the if condition. Try below code
TableRow new_row = new TableRow(this);
for ( i = 0; i < jsonArray.length(); i++)
if (i % 3 == 0 && i != 0) new_row = new TableRow( this );
.......
Switch sw = new Switch( this );
new_row .addView(sw);
It is possible in java. U need to declare that variable outside the if condition. Try below code
TableRow new_row = new TableRow(this);
for ( i = 0; i < jsonArray.length(); i++)
if (i % 3 == 0 && i != 0) new_row = new TableRow( this );
.......
Switch sw = new Switch( this );
new_row .addView(sw);
answered Nov 10 at 5:43
Lucefer
9961511
9961511
add a comment |
add a comment |
up vote
0
down vote
EDIT: Solved by implementing grid view, that is more suitable for this task.
add a comment |
up vote
0
down vote
EDIT: Solved by implementing grid view, that is more suitable for this task.
add a comment |
up vote
0
down vote
up vote
0
down vote
EDIT: Solved by implementing grid view, that is more suitable for this task.
EDIT: Solved by implementing grid view, that is more suitable for this task.
answered Nov 12 at 7:41
B.Ondrej
589
589
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233767%2fadd-next-row-dynamically-after-third-column%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is mean exactly about this sentence of u ??? (But this is not possible in java i guess)
– hamid keyhani
Nov 10 at 6:42
i updated my question adding the error code
– B.Ondrej
Nov 10 at 6:58