Omar Abdelhafiz Omar Abdelhafiz - 1 month ago 8
Android Question

I want to set the code .tostring but it isn't available

In the line of code marked by comment I want to put townHallLvl but it needs to be string so i tried to use .toString but it wasn't available.
Is there another solution or I made something wrong.

package com.example.android.planmyclash;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

//set buildings' values
int townHallLvl = 1;

//declare ids
TextView townHallText = (TextView) findViewById(R.id.town_hall_lvl);


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setValues();

}

public void setValues(){
townHallText.setText(); //this line <----
}

}

Answer

Use

townHallText.setText(String.valueOf(townHallLvl)); 

in order to convert the integer to a String.

Comments