1

我有一个函数 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(...)

我想要做的是显示一些东西(例如“正在加载”)来告诉用户正在填充列表,然后在 findLocalEvents() 函数最终完成运行时显示所有项目。谢谢。

4

1 回答 1

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(); 
    }

然后在可运行时加载 ListView

private Runnable categoriesReturned = new Runnable() {

        public void run() {
               //load listview
            }
};
于 2012-04-18T14:23:07.053 回答