私の 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();
私のonclickメソッド
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();
問題:
進行状況ダイアログは完全に表示されており、データベース内の位置も変更されています。しかし、グリッドビューは更新されていません。つまり、すべての作業が完了すると、進行状況ダイアログが消え、画面が空白になります。
私が間違っているところを助けてください。