簡體   English   中英

setText-無法解析方法

[英]setText - cannot resolve method

可以肯定的是,這是一個愚蠢的問題,但我無法弄清楚。

我正在嘗試將日期選擇器返回的整數轉換為字符串。 該代碼在day是感興趣的整數的地方有效

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

這段代碼給了我無法解決方法setText的錯誤

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

我不明白為什么除非使用視圖,否則無法將int轉換為字符串?

是這個,你想做什么。

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

因為stText mthod僅用於在android的某些視圖上設置文本,如TextView,EditText,Button。

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

如果day是整數值,則可以通過以下方式設置整數值:

dateButton.setText(day+"");

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

要么

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

代替

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

嘗試這個

dateButton.setText(day+"");

您必須實例化該對象,然后再調用它,我對此也是陌生的

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

成為

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

setText必須應用於包含在其中的類或setText方法的超類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM