【发布时间】:2016-01-10 22:11:21
【问题描述】:
我有一个由 expandListAdpater 填充的 Textview 的 ArrayList,我的目标是更改 textView 的值,但由于某种原因它只能工作一次。我尝试了不同的计时器,试图将我的处理程序绑定到 ui 线程,但它永远无法工作。这是我的代码。请帮忙! Expandlistadapter…
TextView mytexts= ButterKnife.findById(view, R.id.mytexts);
mySubSections.add(new ConstructForKeepingTextviewsForUpdate(mytexts));
// I got about 10 more textviews , this is an example
public class ConstructForKeepingTextviewsForUpdate {
private TextView getTextviewToBeUpdated() {
return textviewToBeUpdated;
}
public void SetVal(String t){
getTextviewToBeUpdated().setText(t);
}
TextView textviewToBeUpdated;
public ConstructForKeepingTextviewsForUpdate(TextView textviewToBeUpdated) {
this.textviewToBeUpdated = textviewToBeUpdated;
}
}
in onCreate I run this
private void pleaseWork(){
new Timer().schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
updateNumbersInLoop();
}
});
}
}, 0, 1000);
}
public static void updateNumbersInLoop() {
for (ConstructForKeepingTextviewsForUpdate subSec : mySubSections){
String datext = dbHelper.getValue (computedValue);
subSec.SetVal(datext);
}
}
//The getValue function works , I can see the correct value, but the settext works only once, at the first time.
【问题讨论】:
标签: android multithreading settext android-runonuithread