Creating a GridView based on user input using a for loop
up vote
-1
down vote
favorite
I am trying to create a GridView that is based on the user input.
If the users input is x then the GridView shall show x elements. The problem is I don't want to have elements in GridView that starts with 0, as an Array in Java starts with index 0.
Here is a code snippet:
int numberOfTables=10; //let's say this is user input
String gridViewStrings = new String[numberOfTables];
for(int i =0; i<numberOfTables; i++){
gridViewStrings[i]="Table " +i;
The table descriptions should not start with 0, it should start with 1.
I tried to increment the array size by +1 but I get a BoundofException.
When you compile the code the output is :
Table0, Table1, Table2,...,Table9
The output I want is :
Table 1, Table2,...,Table10
How can I handle this ?
add a comment |
up vote
-1
down vote
favorite
I am trying to create a GridView that is based on the user input.
If the users input is x then the GridView shall show x elements. The problem is I don't want to have elements in GridView that starts with 0, as an Array in Java starts with index 0.
Here is a code snippet:
int numberOfTables=10; //let's say this is user input
String gridViewStrings = new String[numberOfTables];
for(int i =0; i<numberOfTables; i++){
gridViewStrings[i]="Table " +i;
The table descriptions should not start with 0, it should start with 1.
I tried to increment the array size by +1 but I get a BoundofException.
When you compile the code the output is :
Table0, Table1, Table2,...,Table9
The output I want is :
Table 1, Table2,...,Table10
How can I handle this ?
1
If you just want an output Table 1 wheniis zero and so on, why not just writei+1in the code"Table "+(i+1)
– PradyumanDixit
Nov 19 at 15:15
@PradyumanDixit thank you, sometimes one is unable to see the wood for the trees :P
– Blnpwr
Nov 19 at 15:17
@BInpwr no worries, glad to help :)
– PradyumanDixit
Nov 19 at 15:18
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am trying to create a GridView that is based on the user input.
If the users input is x then the GridView shall show x elements. The problem is I don't want to have elements in GridView that starts with 0, as an Array in Java starts with index 0.
Here is a code snippet:
int numberOfTables=10; //let's say this is user input
String gridViewStrings = new String[numberOfTables];
for(int i =0; i<numberOfTables; i++){
gridViewStrings[i]="Table " +i;
The table descriptions should not start with 0, it should start with 1.
I tried to increment the array size by +1 but I get a BoundofException.
When you compile the code the output is :
Table0, Table1, Table2,...,Table9
The output I want is :
Table 1, Table2,...,Table10
How can I handle this ?
I am trying to create a GridView that is based on the user input.
If the users input is x then the GridView shall show x elements. The problem is I don't want to have elements in GridView that starts with 0, as an Array in Java starts with index 0.
Here is a code snippet:
int numberOfTables=10; //let's say this is user input
String gridViewStrings = new String[numberOfTables];
for(int i =0; i<numberOfTables; i++){
gridViewStrings[i]="Table " +i;
The table descriptions should not start with 0, it should start with 1.
I tried to increment the array size by +1 but I get a BoundofException.
When you compile the code the output is :
Table0, Table1, Table2,...,Table9
The output I want is :
Table 1, Table2,...,Table10
How can I handle this ?
edited Nov 19 at 16:34
Kling Klang
32.1k156287
32.1k156287
asked Nov 19 at 15:11
Blnpwr
5141625
5141625
1
If you just want an output Table 1 wheniis zero and so on, why not just writei+1in the code"Table "+(i+1)
– PradyumanDixit
Nov 19 at 15:15
@PradyumanDixit thank you, sometimes one is unable to see the wood for the trees :P
– Blnpwr
Nov 19 at 15:17
@BInpwr no worries, glad to help :)
– PradyumanDixit
Nov 19 at 15:18
add a comment |
1
If you just want an output Table 1 wheniis zero and so on, why not just writei+1in the code"Table "+(i+1)
– PradyumanDixit
Nov 19 at 15:15
@PradyumanDixit thank you, sometimes one is unable to see the wood for the trees :P
– Blnpwr
Nov 19 at 15:17
@BInpwr no worries, glad to help :)
– PradyumanDixit
Nov 19 at 15:18
1
1
If you just want an output Table 1 when
i is zero and so on, why not just write i+1 in the code "Table "+(i+1)– PradyumanDixit
Nov 19 at 15:15
If you just want an output Table 1 when
i is zero and so on, why not just write i+1 in the code "Table "+(i+1)– PradyumanDixit
Nov 19 at 15:15
@PradyumanDixit thank you, sometimes one is unable to see the wood for the trees :P
– Blnpwr
Nov 19 at 15:17
@PradyumanDixit thank you, sometimes one is unable to see the wood for the trees :P
– Blnpwr
Nov 19 at 15:17
@BInpwr no worries, glad to help :)
– PradyumanDixit
Nov 19 at 15:18
@BInpwr no worries, glad to help :)
– PradyumanDixit
Nov 19 at 15:18
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
for(int i =1;i<numberOfTables; i++){ }
Try making your i to be 1. This might make the loop start at one not zero. and you moght not get an error
or you can try i+1
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
for(int i =1;i<numberOfTables; i++){ }
Try making your i to be 1. This might make the loop start at one not zero. and you moght not get an error
or you can try i+1
add a comment |
up vote
1
down vote
for(int i =1;i<numberOfTables; i++){ }
Try making your i to be 1. This might make the loop start at one not zero. and you moght not get an error
or you can try i+1
add a comment |
up vote
1
down vote
up vote
1
down vote
for(int i =1;i<numberOfTables; i++){ }
Try making your i to be 1. This might make the loop start at one not zero. and you moght not get an error
or you can try i+1
for(int i =1;i<numberOfTables; i++){ }
Try making your i to be 1. This might make the loop start at one not zero. and you moght not get an error
or you can try i+1
answered Nov 19 at 15:16
ElectronSz
346
346
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%2f53377542%2fcreating-a-gridview-based-on-user-input-using-a-for-loop%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
1
If you just want an output Table 1 when
iis zero and so on, why not just writei+1in the code"Table "+(i+1)– PradyumanDixit
Nov 19 at 15:15
@PradyumanDixit thank you, sometimes one is unable to see the wood for the trees :P
– Blnpwr
Nov 19 at 15:17
@BInpwr no worries, glad to help :)
– PradyumanDixit
Nov 19 at 15:18