我有一个Runnable
类可以为我的复合列表视图计算模型值,在该可运行文件中,自定义线程中有一个 UI 线程。我有适配器的notifyDataSetChanged()
调用,但是在notifyDataSetChanged()
我尝试更新主布局中的一些 TextView 值之后。问题是在运行 TextView 时首先更新,然后才是 ListViews 并更新。这意味着notifyDataSetChanged()
自Adapter
定义类最后更新,这不适合我。是否有可能同步这些屏幕更新?
这是示例代码:
public class TestRunnable implements Runnable {
private TestAdapter adapter;
@Override
public void run() {
Context.runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
MainActivity.setTextViewValue("Something...");
}
});
}
}
public class TestAdapter extends ArrayAdapter<TestModel> {
@Override
public View getView(final int position, View view, ViewGroup parent) {
View row = view;
TestHolder holder;
Boolean rowIsNew = false;
if (row == null) {
rowIsNew = true;
LayoutInflater layoutInflater = ((Activity) context)
.getLayoutInflater();
row = layoutInflater.inflate(layoutResourceId, parent, false);
holder = new TestHolder();
...
row.setTag(holder);
} else {
holder = (TestHolder) row.getTag();
}
TestModel testModel = data.get(position);
holder.property = testModel.property;
...
if (rowIsNew) {
holder.....setTypeface(...);
holder.....setTypeface(...);
}
return row;
}
}