Android Studio translate code from kotlin to java












-1















I am new to android studio but have come from learning Java in eclipse through university. I've being following along with a simple tutorial that is coded in kotlin however I wanted to create it in Java (although from what I have learnt kotlin is less repetitive). I want to translate the code below from kotlin to java:



val rollButton = findViewByID<Button>(R.id.rollButton)
val resultsTextView= findViewByID<TextView>(R.id.resultsTextView)
val seekBar= findViewByID<seekBar>(R.id.seekBar)

rollButton.setOnClickListener {
val rand = Random().nextInt(seekBar.progress) + 1
resultsTextView.text = rand.toString()









share|improve this question

























  • There's an answer for a similar question here stackoverflow.com/a/40762755/1195507

    – rvazquezglez
    Nov 21 '18 at 6:22






  • 2





    Possible duplicate of How to convert a kotlin source file to a java source file

    – rvazquezglez
    Nov 21 '18 at 6:24
















-1















I am new to android studio but have come from learning Java in eclipse through university. I've being following along with a simple tutorial that is coded in kotlin however I wanted to create it in Java (although from what I have learnt kotlin is less repetitive). I want to translate the code below from kotlin to java:



val rollButton = findViewByID<Button>(R.id.rollButton)
val resultsTextView= findViewByID<TextView>(R.id.resultsTextView)
val seekBar= findViewByID<seekBar>(R.id.seekBar)

rollButton.setOnClickListener {
val rand = Random().nextInt(seekBar.progress) + 1
resultsTextView.text = rand.toString()









share|improve this question

























  • There's an answer for a similar question here stackoverflow.com/a/40762755/1195507

    – rvazquezglez
    Nov 21 '18 at 6:22






  • 2





    Possible duplicate of How to convert a kotlin source file to a java source file

    – rvazquezglez
    Nov 21 '18 at 6:24














-1












-1








-1








I am new to android studio but have come from learning Java in eclipse through university. I've being following along with a simple tutorial that is coded in kotlin however I wanted to create it in Java (although from what I have learnt kotlin is less repetitive). I want to translate the code below from kotlin to java:



val rollButton = findViewByID<Button>(R.id.rollButton)
val resultsTextView= findViewByID<TextView>(R.id.resultsTextView)
val seekBar= findViewByID<seekBar>(R.id.seekBar)

rollButton.setOnClickListener {
val rand = Random().nextInt(seekBar.progress) + 1
resultsTextView.text = rand.toString()









share|improve this question
















I am new to android studio but have come from learning Java in eclipse through university. I've being following along with a simple tutorial that is coded in kotlin however I wanted to create it in Java (although from what I have learnt kotlin is less repetitive). I want to translate the code below from kotlin to java:



val rollButton = findViewByID<Button>(R.id.rollButton)
val resultsTextView= findViewByID<TextView>(R.id.resultsTextView)
val seekBar= findViewByID<seekBar>(R.id.seekBar)

rollButton.setOnClickListener {
val rand = Random().nextInt(seekBar.progress) + 1
resultsTextView.text = rand.toString()






java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 17:56









Jayson Minard

39.5k17109173




39.5k17109173










asked Nov 21 '18 at 5:44









Ned_KellyNed_Kelly

52




52













  • There's an answer for a similar question here stackoverflow.com/a/40762755/1195507

    – rvazquezglez
    Nov 21 '18 at 6:22






  • 2





    Possible duplicate of How to convert a kotlin source file to a java source file

    – rvazquezglez
    Nov 21 '18 at 6:24



















  • There's an answer for a similar question here stackoverflow.com/a/40762755/1195507

    – rvazquezglez
    Nov 21 '18 at 6:22






  • 2





    Possible duplicate of How to convert a kotlin source file to a java source file

    – rvazquezglez
    Nov 21 '18 at 6:24

















There's an answer for a similar question here stackoverflow.com/a/40762755/1195507

– rvazquezglez
Nov 21 '18 at 6:22





There's an answer for a similar question here stackoverflow.com/a/40762755/1195507

– rvazquezglez
Nov 21 '18 at 6:22




2




2





Possible duplicate of How to convert a kotlin source file to a java source file

– rvazquezglez
Nov 21 '18 at 6:24





Possible duplicate of How to convert a kotlin source file to a java source file

– rvazquezglez
Nov 21 '18 at 6:24












4 Answers
4






active

oldest

votes


















0














Here you go



Button rollButton=findViewById(R.id.rollButton);
TextView resultTexView=findViewById(R.id.resultsTextView);
SeekBar seekBar=findViewById(R.id.seekBar);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int rand = Random().nextInt(seekBar.progress) + 1
resultsTextView.setText(rand.toString());
}
});


You're using resultsTextView.setText inside button click listener so maybe that need to declare globally inside class.






share|improve this answer































    1














    In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.






    share|improve this answer































      0














      this is a simple convert, just do this ;-)



      Button rollButton = findViewByID(R.id.rollButton);
      TextView resultsTextView = findViewByID(R.id.resultsTextView);
      seekBar seekBar = findViewByID(R.id.seekBar);

      rollButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
      int rand = Random().nextInt(seekBar.progress) + 1 ;
      resultsTextView.setText(String.valueOf(rand));
      }
      });





      share|improve this answer































        0














        Button rollButton = findViewById(R.id.rollButton);
        TextView resultsTextView = findViewById(R.id.resultsTextView);
        Seekbar seekbar = findViewById(R.id.seekbar);

        rollButton.setOnClickListener(new View.OnClickListener {
        @Override
        public void onClick (View view){
        int rand = Random().nextInt(seekBar.progress) + 1;
        resultsTextView.setText(String.valueOf(rand));
        }
        });





        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',
          autoActivateHeartbeat: false,
          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%2f53405900%2fandroid-studio-translate-code-from-kotlin-to-java%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Here you go



          Button rollButton=findViewById(R.id.rollButton);
          TextView resultTexView=findViewById(R.id.resultsTextView);
          SeekBar seekBar=findViewById(R.id.seekBar);

          button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
          int rand = Random().nextInt(seekBar.progress) + 1
          resultsTextView.setText(rand.toString());
          }
          });


          You're using resultsTextView.setText inside button click listener so maybe that need to declare globally inside class.






          share|improve this answer




























            0














            Here you go



            Button rollButton=findViewById(R.id.rollButton);
            TextView resultTexView=findViewById(R.id.resultsTextView);
            SeekBar seekBar=findViewById(R.id.seekBar);

            button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            int rand = Random().nextInt(seekBar.progress) + 1
            resultsTextView.setText(rand.toString());
            }
            });


            You're using resultsTextView.setText inside button click listener so maybe that need to declare globally inside class.






            share|improve this answer


























              0












              0








              0







              Here you go



              Button rollButton=findViewById(R.id.rollButton);
              TextView resultTexView=findViewById(R.id.resultsTextView);
              SeekBar seekBar=findViewById(R.id.seekBar);

              button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
              int rand = Random().nextInt(seekBar.progress) + 1
              resultsTextView.setText(rand.toString());
              }
              });


              You're using resultsTextView.setText inside button click listener so maybe that need to declare globally inside class.






              share|improve this answer













              Here you go



              Button rollButton=findViewById(R.id.rollButton);
              TextView resultTexView=findViewById(R.id.resultsTextView);
              SeekBar seekBar=findViewById(R.id.seekBar);

              button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
              int rand = Random().nextInt(seekBar.progress) + 1
              resultsTextView.setText(rand.toString());
              }
              });


              You're using resultsTextView.setText inside button click listener so maybe that need to declare globally inside class.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 21 '18 at 5:50









              QueendevelopersQueendevelopers

              6815




              6815

























                  1














                  In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.






                  share|improve this answer




























                    1














                    In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.






                    share|improve this answer


























                      1












                      1








                      1







                      In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.






                      share|improve this answer













                      In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 21 '18 at 5:55









                      AmirAmir

                      159214




                      159214























                          0














                          this is a simple convert, just do this ;-)



                          Button rollButton = findViewByID(R.id.rollButton);
                          TextView resultsTextView = findViewByID(R.id.resultsTextView);
                          seekBar seekBar = findViewByID(R.id.seekBar);

                          rollButton.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                          int rand = Random().nextInt(seekBar.progress) + 1 ;
                          resultsTextView.setText(String.valueOf(rand));
                          }
                          });





                          share|improve this answer




























                            0














                            this is a simple convert, just do this ;-)



                            Button rollButton = findViewByID(R.id.rollButton);
                            TextView resultsTextView = findViewByID(R.id.resultsTextView);
                            seekBar seekBar = findViewByID(R.id.seekBar);

                            rollButton.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                            int rand = Random().nextInt(seekBar.progress) + 1 ;
                            resultsTextView.setText(String.valueOf(rand));
                            }
                            });





                            share|improve this answer


























                              0












                              0








                              0







                              this is a simple convert, just do this ;-)



                              Button rollButton = findViewByID(R.id.rollButton);
                              TextView resultsTextView = findViewByID(R.id.resultsTextView);
                              seekBar seekBar = findViewByID(R.id.seekBar);

                              rollButton.setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View view) {
                              int rand = Random().nextInt(seekBar.progress) + 1 ;
                              resultsTextView.setText(String.valueOf(rand));
                              }
                              });





                              share|improve this answer













                              this is a simple convert, just do this ;-)



                              Button rollButton = findViewByID(R.id.rollButton);
                              TextView resultsTextView = findViewByID(R.id.resultsTextView);
                              seekBar seekBar = findViewByID(R.id.seekBar);

                              rollButton.setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View view) {
                              int rand = Random().nextInt(seekBar.progress) + 1 ;
                              resultsTextView.setText(String.valueOf(rand));
                              }
                              });






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 21 '18 at 5:50









                              FarrokhFarrokh

                              1,0631617




                              1,0631617























                                  0














                                  Button rollButton = findViewById(R.id.rollButton);
                                  TextView resultsTextView = findViewById(R.id.resultsTextView);
                                  Seekbar seekbar = findViewById(R.id.seekbar);

                                  rollButton.setOnClickListener(new View.OnClickListener {
                                  @Override
                                  public void onClick (View view){
                                  int rand = Random().nextInt(seekBar.progress) + 1;
                                  resultsTextView.setText(String.valueOf(rand));
                                  }
                                  });





                                  share|improve this answer




























                                    0














                                    Button rollButton = findViewById(R.id.rollButton);
                                    TextView resultsTextView = findViewById(R.id.resultsTextView);
                                    Seekbar seekbar = findViewById(R.id.seekbar);

                                    rollButton.setOnClickListener(new View.OnClickListener {
                                    @Override
                                    public void onClick (View view){
                                    int rand = Random().nextInt(seekBar.progress) + 1;
                                    resultsTextView.setText(String.valueOf(rand));
                                    }
                                    });





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      Button rollButton = findViewById(R.id.rollButton);
                                      TextView resultsTextView = findViewById(R.id.resultsTextView);
                                      Seekbar seekbar = findViewById(R.id.seekbar);

                                      rollButton.setOnClickListener(new View.OnClickListener {
                                      @Override
                                      public void onClick (View view){
                                      int rand = Random().nextInt(seekBar.progress) + 1;
                                      resultsTextView.setText(String.valueOf(rand));
                                      }
                                      });





                                      share|improve this answer













                                      Button rollButton = findViewById(R.id.rollButton);
                                      TextView resultsTextView = findViewById(R.id.resultsTextView);
                                      Seekbar seekbar = findViewById(R.id.seekbar);

                                      rollButton.setOnClickListener(new View.OnClickListener {
                                      @Override
                                      public void onClick (View view){
                                      int rand = Random().nextInt(seekBar.progress) + 1;
                                      resultsTextView.setText(String.valueOf(rand));
                                      }
                                      });






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 21 '18 at 5:56









                                      Tarak BhawalkarTarak Bhawalkar

                                      193




                                      193






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405900%2fandroid-studio-translate-code-from-kotlin-to-java%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

                                          MongoDB - Not Authorized To Execute Command

                                          How to fix TextFormField cause rebuild widget in Flutter

                                          Npm cannot find a required file even through it is in the searched directory