在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