我有一个函数findLocalEvents(),它返回我想在ListView中显示的项目列表。然后,在填充listview的活动的onCreate()中,我有以下代码:
View header = (View) getLayoutInflater().inflate(
R.layout.list_header_view, null);
getListView().addHeaderView(header);
TextView title = (TextView) findViewById(R.id.list_view_name);
title.setText("Events nearby: ");
setListAdapter(new ArrayAdapter<String>(this, R.layout.event_list_item,
findLocalEvents()));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
// LIST ITEM IS CLICKED
lv.setOnItemClickListener(...)
我想要做的是显示某些内容(例如“正在加载”)以告诉用户正在填充列表,然后在findLocalEvents()函数最终完成运行时显示所有项目。感谢。
答案 0 :(得分:0)
这里需要线程来显示加载消息。以下代码将为您提供如何
的建议ProgressDialog dialog = ProgressDialog.show(this, "Validating Postcode/Zipcode",
"Please wait...!", true);
startThread();
private void startThread() {
new Thread(new Runnable() {
public void run() {
try {
ArrayList<t> arr = NetworkCalls.fetchCategoriesByZipCode();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
runOnUiThread(categoriesReturned);
}
}).start();
}
然后在runnable上加载ListView
private Runnable categoriesReturned = new Runnable() {
public void run() {
//load listview
}
};