Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:57:07+00:00 2026-06-12T20:57:07+00:00

In my Android app I have a grid showing images as items. When I

  • 0

In my Android app I have a grid showing images as items. When I click a button the items should be change their positions. I am populating this grid through a cursor adapter. Previously it was working fine but was taking some time to change the positions of the images and refresh the grid once again. So for that i implemented a progress dialog, so that user could understand that something is going on.

Here is my code so far.

My Handler

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();

My onclick method

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();

Problems:

The progress dialog is showing eprfectly, the positions are also changed in the database. but the gridview is not refreshing. I mean after all works done the progress dialog disappears and the screen becomes blank.

Please help me where i am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:57:08+00:00Added an answer on June 12, 2026 at 8:57 pm

    I think the problem is that you are assigning a new adapter on the handler, but not calling to NotifyDataSetChanged() on the main thread, that’s maybe why is not updating the grid.

    Also, why not use AsyncTasks?

    public class LoadAsyncTask extends AsyncTask<Void, Void, Boolean> {
        Context context;
    
        public LoadAsyncTask(Context context) {
            this.context = context;         
        }
    
        protected void onPreExecute() {
        }
    
        protected Boolean doInBackground(Void... v) {
            DBAdapter adapter = new DBAdapter(context);
            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();
    
            DBAdapter adapter = new DBAdapter(context);
            adapter.open();
            Cursor cursor = adapter.getAllImages();
            adapter.close();
            startManagingCursor(cursor);
            cursorAdapter.changeCursor(cursor); //My cursor adapter
            gridView.setAdapter(cursorAdapter);
            cursor.close();                
            return true;
        }
    
        protected void onPostExecute(Boolean success) {
            if (success) {
                //This will be executed on the main activity thread
                cursorAdapter.notifyDataSetChanged();
            } else {
                showError();
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 50 images with in a grid view within my Android app.
I have a Grid View in my android app.I am loading images to the
I have an Android app which presents a grid of items in my MainActivity.
I have android app . i should pass the data from android to web
In my android app I have this scenario - I have a Gallery where
i have a grid view which contain images when click on one image it
In my android app I have a gridview that I want to show images
I'm developing a Android App. This App have an SQLite Database. This Database have
In my Android app I have an image that loads in. With this image
In my android app I have used InMobi ad sdk to show banner ad's.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.