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秒后几秒, 并且不断增长并终于接近 。
<强度 > 溶解 强度 > :
我不敢相信我看不到这一点。 线条是从人群开始的, 并导致无尽循环。 我不得不把它放在调用查询和数据库查询之后。