简体   繁体   中英

setText - cannot resolve method

Pretty sure this is a stupid question but I can't figure this out.

I am trying to get an integer returned by a datepicker to a string. This code works where day is the integer of interest

dateButton = (Button) findViewById(R.id.dateButton);
dateButton.setText((Integer.toString(day));

This code gives me the error that cannot resolve method setText

String yearString = "";
yearString.setText(Integer.toString(year)); 

I don't understand why I cant convert the int to a string unless I use a view?

Is this, what you want to do.

int year = 2014;
String yearString = Integer.toString(year); 

Because stText mthod is only for setting text on certain views on android likeTextView, EditText, Button.

dateButton = (Button) findViewById(R.id.dateButton);
dateButton.settext(Interger.Valueof(day));

You can set integer value by following ways if day is an integer value,

dateButton.setText(day+"");

or by

dateButton.setText(String.valueOf(day));

or

dateButton.setText(Integer.toString(day));

Instead of

dateButton.setText((Integer.toString(day));

Try this

dateButton.setText(day+"");

you have to instantiate the object before you call it view I am new to this also So this

((TextView) findViewById(R.id.now_playing_text)).setText(trackTitle)

Becomes

TextView Title = (TextView) findViewById(R.id.now_playing_text);
Title.setText(trackTitle);

setText must be applied on an a class that contains in it or it supper classes the setText method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM