2015-03-13 89 views
2

我開始使用TextView的findViewWithTag()方法來動態更新文本,並在更新UI時遇到問題。該方法的作用在於它找到了TextView,並且我可以設置文本。我通過檢查代碼中的對象來驗證這一點。儘管該方法返回正確的TextView和文本屬性更新,但UI不會更新。所有代碼都在UI線程上執行,並且findViewById()方法按預期工作。我在這裏做錯了什麼?Android - findViewWithTag與findViewById

//This works as expected correctly 
((TextView) findViewById(R.id.textview)).setText("NEW TEXT"); 

//This updates the test property, but does not update the UI. 
((TextView) view.findViewWithTag("TAG TEXT")).setText("NEW TEXT"); 

這些方法在Activity的onCreate方法中進行了測試。

謝謝。

+0

確保您不使用「標記文本」作爲標籤的另一個瀏覽 – Rami 2015-03-13 20:12:11

回答

0

我做了這樣的事情,它的工作

TextView loginTextView = (TextView) view 
      .findViewById(R.id.welcome_text_login); 
    loginTextView.setTag("hello"); 
    TextView another=(TextView) view.findViewWithTag("hello"); 
    another.setText("signin"); 
+0

我做同樣的事情,並沒有更新我的UI。我想這是一貫的,這很好。當我使用findViewWithTag()時,有些東西會阻止更新。我很難過。 – 2015-03-14 17:57:34

+0

對不起哥們。我不知道爲什麼它沒有更新您的文本 – krishna 2015-03-14 19:34:02