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 ?










share|improve this question




















  • 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












  • @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















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 ?










share|improve this question




















  • 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












  • @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













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 ?










share|improve this question















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 ?







android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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










  • @BInpwr no worries, glad to help :)
    – PradyumanDixit
    Nov 19 at 15:18














  • 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












  • @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












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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 15:16









        ElectronSz

        346




        346






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Feedback on college project

            Futebolista

            Albești (Vaslui)