Wait for click event in a for loop









up vote
0
down vote

favorite












I have an array of images like this:



int fruitList = new int 
R.drawable.apple,
R.drawable.orange,
R.drawable.bannana
;


and an ImageView. For every fruit i want to a) populate the ImageView b) wait for click to open a Dialog (Choose fruit name and do something ...) and repeat for next fruit.



I thought of a for loop but doesn't make sense. I need to wait for the click before going to the next fruit.



Any ideas ??










share|improve this question



























    up vote
    0
    down vote

    favorite












    I have an array of images like this:



    int fruitList = new int 
    R.drawable.apple,
    R.drawable.orange,
    R.drawable.bannana
    ;


    and an ImageView. For every fruit i want to a) populate the ImageView b) wait for click to open a Dialog (Choose fruit name and do something ...) and repeat for next fruit.



    I thought of a for loop but doesn't make sense. I need to wait for the click before going to the next fruit.



    Any ideas ??










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have an array of images like this:



      int fruitList = new int 
      R.drawable.apple,
      R.drawable.orange,
      R.drawable.bannana
      ;


      and an ImageView. For every fruit i want to a) populate the ImageView b) wait for click to open a Dialog (Choose fruit name and do something ...) and repeat for next fruit.



      I thought of a for loop but doesn't make sense. I need to wait for the click before going to the next fruit.



      Any ideas ??










      share|improve this question















      I have an array of images like this:



      int fruitList = new int 
      R.drawable.apple,
      R.drawable.orange,
      R.drawable.bannana
      ;


      and an ImageView. For every fruit i want to a) populate the ImageView b) wait for click to open a Dialog (Choose fruit name and do something ...) and repeat for next fruit.



      I thought of a for loop but doesn't make sense. I need to wait for the click before going to the next fruit.



      Any ideas ??







      android android-drawable android-dialog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 18:24









      Kling Klang

      32k156286




      32k156286










      asked Nov 10 at 16:56









      user2788573

      4416




      4416






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          1. Hold an index for your position along the fruitList

          2. Set an onClickListener on the Image View.

          3. Create a Dialog in the onClickListener


          4. Subscribe any clicks in the dialog, and in that subscription change the fruit by incrementing your index (maybe % fruitList.size?)

          5. In the onClickListener launch the dialog

          The key difference between app development and smaller programs is that apps are all event based. A for loop isn't suited for this kind of task.






          share|improve this answer




















          • Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
            – user2788573
            Nov 12 at 17:06

















          up vote
          1
          down vote













          You can use Carousel view for it. You can use following repositories for it. Choose what you want



          • https://github.com/sayyam/carouselview

          • https://github.com/Azoft/CarouselLayoutManager

          • https://android-arsenal.com/tag/154

          • https://medium.com/@lobothijau/create-carousel-easily-in-android-app-with-carouselview-6cbf5ef500a9





          share|improve this answer




















          • This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
            – user2788573
            Nov 10 at 17:23










          • you can customize github.com/sayyam/carouselview as u wish
            – Lucefer
            Nov 10 at 17:27










          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%2f53241241%2fwait-for-click-event-in-a-for-loop%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          1. Hold an index for your position along the fruitList

          2. Set an onClickListener on the Image View.

          3. Create a Dialog in the onClickListener


          4. Subscribe any clicks in the dialog, and in that subscription change the fruit by incrementing your index (maybe % fruitList.size?)

          5. In the onClickListener launch the dialog

          The key difference between app development and smaller programs is that apps are all event based. A for loop isn't suited for this kind of task.






          share|improve this answer




















          • Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
            – user2788573
            Nov 12 at 17:06














          up vote
          1
          down vote



          accepted










          1. Hold an index for your position along the fruitList

          2. Set an onClickListener on the Image View.

          3. Create a Dialog in the onClickListener


          4. Subscribe any clicks in the dialog, and in that subscription change the fruit by incrementing your index (maybe % fruitList.size?)

          5. In the onClickListener launch the dialog

          The key difference between app development and smaller programs is that apps are all event based. A for loop isn't suited for this kind of task.






          share|improve this answer




















          • Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
            – user2788573
            Nov 12 at 17:06












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          1. Hold an index for your position along the fruitList

          2. Set an onClickListener on the Image View.

          3. Create a Dialog in the onClickListener


          4. Subscribe any clicks in the dialog, and in that subscription change the fruit by incrementing your index (maybe % fruitList.size?)

          5. In the onClickListener launch the dialog

          The key difference between app development and smaller programs is that apps are all event based. A for loop isn't suited for this kind of task.






          share|improve this answer












          1. Hold an index for your position along the fruitList

          2. Set an onClickListener on the Image View.

          3. Create a Dialog in the onClickListener


          4. Subscribe any clicks in the dialog, and in that subscription change the fruit by incrementing your index (maybe % fruitList.size?)

          5. In the onClickListener launch the dialog

          The key difference between app development and smaller programs is that apps are all event based. A for loop isn't suited for this kind of task.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 21:42









          bkach

          6461522




          6461522











          • Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
            – user2788573
            Nov 12 at 17:06
















          • Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
            – user2788573
            Nov 12 at 17:06















          Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
          – user2788573
          Nov 12 at 17:06




          Thanks man. I ended doing what you said and added an interface and a listener in onDismiss of the dialog to increment the index of the array.
          – user2788573
          Nov 12 at 17:06












          up vote
          1
          down vote













          You can use Carousel view for it. You can use following repositories for it. Choose what you want



          • https://github.com/sayyam/carouselview

          • https://github.com/Azoft/CarouselLayoutManager

          • https://android-arsenal.com/tag/154

          • https://medium.com/@lobothijau/create-carousel-easily-in-android-app-with-carouselview-6cbf5ef500a9





          share|improve this answer




















          • This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
            – user2788573
            Nov 10 at 17:23










          • you can customize github.com/sayyam/carouselview as u wish
            – Lucefer
            Nov 10 at 17:27














          up vote
          1
          down vote













          You can use Carousel view for it. You can use following repositories for it. Choose what you want



          • https://github.com/sayyam/carouselview

          • https://github.com/Azoft/CarouselLayoutManager

          • https://android-arsenal.com/tag/154

          • https://medium.com/@lobothijau/create-carousel-easily-in-android-app-with-carouselview-6cbf5ef500a9





          share|improve this answer




















          • This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
            – user2788573
            Nov 10 at 17:23










          • you can customize github.com/sayyam/carouselview as u wish
            – Lucefer
            Nov 10 at 17:27












          up vote
          1
          down vote










          up vote
          1
          down vote









          You can use Carousel view for it. You can use following repositories for it. Choose what you want



          • https://github.com/sayyam/carouselview

          • https://github.com/Azoft/CarouselLayoutManager

          • https://android-arsenal.com/tag/154

          • https://medium.com/@lobothijau/create-carousel-easily-in-android-app-with-carouselview-6cbf5ef500a9





          share|improve this answer












          You can use Carousel view for it. You can use following repositories for it. Choose what you want



          • https://github.com/sayyam/carouselview

          • https://github.com/Azoft/CarouselLayoutManager

          • https://android-arsenal.com/tag/154

          • https://medium.com/@lobothijau/create-carousel-easily-in-android-app-with-carouselview-6cbf5ef500a9






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 17:14









          Lucefer

          9661511




          9661511











          • This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
            – user2788573
            Nov 10 at 17:23










          • you can customize github.com/sayyam/carouselview as u wish
            – Lucefer
            Nov 10 at 17:27
















          • This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
            – user2788573
            Nov 10 at 17:23










          • you can customize github.com/sayyam/carouselview as u wish
            – Lucefer
            Nov 10 at 17:27















          This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
          – user2788573
          Nov 10 at 17:23




          This looks like a gallery. I want to display one image at a time, maybe some animation and change it after the AlertDialog has closed
          – user2788573
          Nov 10 at 17:23












          you can customize github.com/sayyam/carouselview as u wish
          – Lucefer
          Nov 10 at 17:27




          you can customize github.com/sayyam/carouselview as u wish
          – Lucefer
          Nov 10 at 17:27

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241241%2fwait-for-click-event-in-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







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3