-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()
Jayson Minard
  • 74,658
  • 30
  • 167
  • 210
Ned_Kelly
  • 59
  • 5
  • There's an answer for a similar question here https://stackoverflow.com/a/40762755/1195507 – rvazquezglez Nov 21 '18 at 06:22
  • 2
    Possible duplicate of [How to convert a kotlin source file to a java source file](https://stackoverflow.com/questions/34957430/how-to-convert-a-kotlin-source-file-to-a-java-source-file) – rvazquezglez Nov 21 '18 at 06:24

4 Answers4

1

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

Amir
  • 179
  • 2
  • 14
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.

Queendevelopers
  • 183
  • 1
  • 15
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));
    }
});
Farrokh
  • 1,109
  • 1
  • 7
  • 18
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));
    }
});