Android Studio translate code from kotlin to java
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

add a comment |
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

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
add a comment |
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

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

java

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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
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.
add a comment |
In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.
add a comment |
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));
}
});
add a comment |
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));
}
});
add a comment |
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
});
}
});
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%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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 21 '18 at 5:50


QueendevelopersQueendevelopers
6815
6815
add a comment |
add a comment |
In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.
add a comment |
In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.
add a comment |
In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.
In Android Studio you can Decompile Kotlin to Java from Menu > Tools > Kotlin -> Decompile Kotlin to Java.
answered Nov 21 '18 at 5:55
AmirAmir
159214
159214
add a comment |
add a comment |
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));
}
});
add a comment |
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));
}
});
add a comment |
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));
}
});
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));
}
});
answered Nov 21 '18 at 5:50


FarrokhFarrokh
1,0631617
1,0631617
add a comment |
add a comment |
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));
}
});
add a comment |
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));
}
});
add a comment |
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));
}
});
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));
}
});
answered Nov 21 '18 at 5:56


Tarak BhawalkarTarak Bhawalkar
193
193
add a comment |
add a comment |
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.
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%2f53405900%2fandroid-studio-translate-code-from-kotlin-to-java%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
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