在我的 Android 应用程序中,我有一个将图像显示为项目的网格。当我单击一个按钮时,项目应该改变它们的位置。我正在通过光标适配器填充此网格。以前它工作正常,但需要一些时间来更改图像的位置并再次刷新网格。因此,为此我实现了一个进度对话框,以便用户可以了解正在发生的事情。
到目前为止,这是我的代码。
我的处理程序
public void handleMessage(Message msg) {
switch (msg.what) {
case PROGRESS_DIALOG_HANDLER_ID:
progressDialog.dismiss(); //ProgressDialog
DBAdapter adapter = new DBAdapter(SplittedImageActivity.this);
adapter.open();
Cursor cursor = adapter.getAllImages();
adapter.close();
startManagingCursor(cursor);
cursorAdapter.changeCursor(cursor); //My cursor adapter
gridView.setAdapter(cursorAdapter);
cursor.close();
我的点击方法
progressDialog = ProgressDialog.show(SplittedImageActivity.this, "", "Please wait...");
new Thread(){
public void run() {
Random random = new Random();
DBAdapter adapter = new DBAdapter(getApplicationContext());
adapter.open();
int childs = gridView.getChildCount(), oldPosition, newPotision;
newPotision = childs-1;
for(int i=0 ; i<childs ; i++){
oldPosition = random.nextInt(m_cGridView.getChildCount());
adapter.updatePosition(oldPosition, newPotision); //updates the position of the images in database
newPotision = oldPosition;
}
adapter.close();
handler.sendEmptyMessage(PROGRESS_DIALOG_HANDLER_ID);
};
}.start();
问题:
进度对话框显示完美,数据库中的位置也发生了变化。但gridview不刷新。我的意思是在完成所有工作后,进度对话框消失并且屏幕变为空白。
请帮助我在哪里做错了?