Reputation: 1033
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?
Upvotes: 0
Views: 24739
Reputation: 11114
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.
Upvotes: 1
Reputation: 5097
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.
Upvotes: 6
Reputation: 110
Instead of
dateButton.setText((Integer.toString(day));
Try this
dateButton.setText(day+"");
Upvotes: 0
Reputation: 2354
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));
Upvotes: 3
Reputation: 832
dateButton = (Button) findViewById(R.id.dateButton);
dateButton.settext(Interger.Valueof(day));
Upvotes: 1