我得到一個錯誤,當我打電話的onCreate()
如何在活動的OnCreate()方法中調用findViewWithTag?
findViewWithTag()
「的方法findViewWithTag(String)
是未定義類型 MainActivity」
有什麼選擇?
我得到一個錯誤,當我打電話的onCreate()
如何在活動的OnCreate()方法中調用findViewWithTag?
findViewWithTag()
「的方法findViewWithTag(String)
是未定義類型 MainActivity」
有什麼選擇?
findViewWithTag()
僅針對View定義。
如果您有使用setContentView(contentView)
設置的活動的contentView參考,則可以使用contentView.findViewWithTag()
。
如果您沒有對該視圖的引用,則還可以使用findViewById(R.id.your_content_view_id).findViewWithTag(tag)
。
它只有findViewWithTag,對不對? – Enigman
該方法是['View#findViewWithTag()'](http://developer.android.com/reference/android/view/View.html#findViewWithTag%28java.lang.Object%29),它不是Activity類。也許你想使用更有用的'findViewById()'方法? – Sam
@Sam no,我真的需要使用findViewWithTag,因爲我必須遍歷許多TextView並設置它們的文本。因此,我已經爲它們中的每一個添加了標籤,從01,02 ...直到26,27。 由於它是一個字符串,因此我訪問標籤比較容易。 有一些只使用他們的ID的出路嗎? – Enigman