簡體   English   中英

TextView setText無法解析類型

[英]TextView setText Cannot resolve type

我正在使用Android Studio,嘗試將文本設置為``文本視圖'',但是每次我這樣做

TextView test = (TextView) findViewById(R.id.testView);
test.setText("fds");

在Android Studio上,我看到Cannot resolve symbol 'setText' 有人可以告訴我我做錯了什么嗎?

setText()將接受您已傳遞的String,因此沒有問題。

造成這種情況的一種可能原因是您沒有在onCreate()onCreateView()編寫代碼。

  1. 如果是Activity ,則需要在onCreate() setContentView()之后使用這些行。
  2. 如果是Fragment ,則需要在onCreateView()擴大view后使用這些行。

第二個原因,您可能還有另一個不同類型的test變量,例如String或其他

暫無
暫無

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

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