English 中文(简体)
单独阅读的目录
原标题:Populating listview in separate thread

在一项活动中,我把需要很多时间的清单加起来,因此,我把这项任务放在一个单独的轨道上,以便显示进展。

I do the following

private void doMyStuff() {
    listItems.clear();
    progressDialog.show();

    new Thread(new Runnable() {
        @Override
        public void run() {                
            for () {
                listItems.add(something to add);
            }
        handler.sendEmptyMessage(0);
        progressDialog.dismiss();
        }
    }).start();
}

private Handler handler = new Handler() {
    public void handleMessage(android.os.Message msg) {
        if (msg.what == 0) {
            adapter.notifyDataSetChanged();
        }
    };
};

我有时会提出非法国家欺骗。 首先,我感到惊讶,因为方案拟定像我通常在标准 Java方案中所做的那样。

b看起来只是“有时”的,在采取逐步分解措施时并不出现。

这导致我对网络进行搜索,我在SO中发现了一些与这一问题有关的问题,我必须承认,我不清楚事情。

当我打电话给通知DataSetChanged()时,只是在read子结束,为什么有时会提出例外。

一些人能否证实我,这种做法是错误的,而且,我相信自己会把自己当作一项任务,或许会给我解释为什么?

我需要取得进展。 显示的糖尿病人可以给我一个简单的例子,说明AyncTask人的名单和进展情况。 5. 人口动态的诊断。

成就

<>>>>>

jtanveer给我回答Asynctask问题。 现在,其他人指出,开除不是手里,我是正确的。

根据jtanveer关于“无用读物”的文章,他们说:

甲型六氯环己烷提供了几种途径,可以从其中之一为HANDLER的其他深层进入宇宙航行联合会。

是否有人知道为什么把被解雇的人放在手里不解决我的问题? 页: 1 项目没有与《倡议》有任何关系? 我在这一点上错了吗?

对我来说,在我的法典中,唯一一个是调制器和进步方言? 欢迎任何评注或解释。

www.un.org/Depts/DGACM/index_spanish.htm

工作为我的具体法典提供了工作答案。 • 在手稿上开台。 我感到惊讶的是,我觉得手在Ui Thread......。

请各位回答。

最佳回答

每当您打电话adapter.notificationDataSetChanged(>;,其中指明了对listItems的任何改动,如发现有任何改动,则将相应地更新我认为引起你的问题的《国际调查》。 页: 1

runOnUiThread(new Runnable() {
    public void run() {
        adapter.notifyDataSetChanged();
    }  
});

页: 1

问题回答

a. 界定如下内部类别:

private class LoadListTask extends AsyncTask<String, Void, Integer> {
    protected void onPreExecute() {
        progressDialog.show();
    }

    protected Integer doInBackground(String... params) {
        for () {
            listItems.add(something to add);
        }
        return 0;
    }

    protected void onPostExecute(Integer result) {
        progressDialog.dismiss();
        if (result == 0) {
           adapter.notifyDataSetChanged();
        }
    }
}

如有必要,请参看article

你们不需要使用AsyncTask,这只是一个方便。

As far as why your current implementation doesn t work sometimes - You should dismiss your progress dialog from the UI thread, so that needs to go in your handler, not your background thread.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签