在java/android API中是否有任何「技巧」與static
或其他內容同時改變片段中具有相同ID的對象中的文本?在鏈接片段中「鏈接」對象的文本
假設我有一個靜態的字符串:
private static String buttonText = "Today";
每個片段有一個按鈕:
Button mButton = (Button) getView().findViewById(R.id.change_button);
mBotton.setText(buttonText);
要改變對片段的文字我做的:
buttonText = "Tomorrow";
mBotton.setText(buttonText);
燦我自動將文本更改爲其他片段?保持List<Button>
我的唯一方法(循環列表並設置每個文本)?
你知道「觀察者模式」 - > http://developer.android.com/reference/java/util/Observer.html – Fildor
@Fildor Nope。現在看。使用昂貴嗎? – Diolor
不,它不貴。 [Observable](http://developer.android.com/reference/java/util/Observable.html)類爲您提供了所需的大部分內容。 – Fildor