Android:ListActivity 和 ArrayAdapter - 显示列表之前排序
我有一个 ListActivity,它有一个 ArrayAdapter 和一个 Filter。我想填充 ArrayAdapter 的项目,过滤结果然后显示它们。无论出于何种原因,都会发生一些奇特的线程,强制显示结果而不先应用过滤器,然后进行过滤。因此,有十分之一秒的时间您可以看到未过滤的结果。
在 ListActivity 上的 UI 线程中运行
private Runnable returnRes = new Runnable() {
public void run() {
if (promotionItems != null && promotionItems.size() > 0) {
for (int i = 0; i < promotionItems.size(); i++)
m_adapter.add(promotionItems.get(i));
}
m_adapter.getFilter().filter(filterString);
m_adapter.notifyDataSetChanged();
m_ProgressDialog.dismiss();
}
};
Ive got a ListActivity that has a ArrayAdapter and a Filter. I want to fill the ArrayAdapter's items up, filter the results then display them. For whatever reason there is some fancy threading going on that forces the result to be displayed without applying the filter first, then it filters. So there is a tenth of a second where you can see non-filtered results.
Run within the UI thread on the ListActivity
private Runnable returnRes = new Runnable() {
public void run() {
if (promotionItems != null && promotionItems.size() > 0) {
for (int i = 0; i < promotionItems.size(); i++)
m_adapter.add(promotionItems.get(i));
}
m_adapter.getFilter().filter(filterString);
m_adapter.notifyDataSetChanged();
m_ProgressDialog.dismiss();
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否看过 ArrayAdapter.setNotifyOnChange(boolean)< /a>?在这种特殊情况下,听起来您想要在将任何项目添加到 ArrayAdapter 之前禁用它。
Have you taken a look on ArrayAdapter.setNotifyOnChange(boolean)? Sounds like it's something you want to disable before adding any of your items to ArrayAdapter in this particular case.