English 中文(简体)
Android - 使用带有列表视图的进度对话框
原标题:Android - using progressdialog with listview

I am collecting data from the calllog, putting it into a database, and querying them into a ListView. With 500 calls it takes around 8 seconds, which looks bad, so I decided to implement a progressdialog to show the user how many items are left to be loaded. Now I am trying with 3 items (there are 3 items in the calllog of the emulator). When the progressdialog finishes, the listview is populated with the 3 items, but then the same 3 items are added again and again making an endless loop.

在填充之前我先把桌子清空, 所以它总是有三张记录。

有什么问题吗?

pd = new ProgressDialog(Calllogs.this);
        pd.setCancelable(true);
        pd.setMessage("Loading...");
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setProgress(0);
        pd.setMax(3);
        pd.show();


        //incrementProgressBy
        new Thread(new Runnable() {                 
            @Override
            public void run() {
                   try
                   {
                    while(pd.getProgress()<=pd.getMax())
                      {
                        Thread.sleep(1000);

//collect data and populate database table
//query data and populate arrays

 handler.sendMessage(handler.obtainMessage());
        if(pd.getProgress()==pd.getMax())
        {
             pd.dismiss();
             adapter = new ListViewCustomAdapter(Calllogs.this, arr_calllog_name, arr_calllog_phone, arr_calllog_type,arr_calllog_duration, arr_calllog_date);
             lv1.post(new Runnable() {
                 public void run() {
                     lv1.setAdapter(adapter);
               }}); 

        }
        }
    }catch(Exception e){}
   }
   }).start();

和处理者:

 private Handler handler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                             super.handleMessage(msg);
                            pd.incrementProgressBy(1);    
                            //pd.dismiss();


                        }
                };

< 坚固 > EDIT < /坚固 > : 我无意中发现整个表群已经成为一个无休止的循环。 我用 Sqlite 数据库浏览器检查了表格, 起初它有21个项目, 在59秒后几秒, 并且不断增长并终于接近 。

<强度 > 溶解 :

我不敢相信我看不到这一点。 线条是从人群开始的, 并导致无尽循环。 我不得不把它放在调用查询和数据库查询之后。

最佳回答

我不敢相信我看不到这一点。 线条是从人群开始的, 并导致无尽循环。 我不得不把它放在调用查询和数据库查询之后。

问题回答

暂无回答




相关问题
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 ...

热门标签