[英]Android lazy list loading from another activity
我有一个函数findLocalEvents(),该函数返回要在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(...)
我要做的是显示一些内容(例如“ Loading”)以告诉用户列表正在填充,然后在findLocalEvents()函数最终完成运行时显示所有项目。 谢谢。
您需要这里的线程来显示加载消息。 以下代码将使您了解如何
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();
}
然后在运行时加载ListView
private Runnable categoriesReturned = new Runnable() {
public void run() {
//load listview
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.