title: Show Progressbar while i get records from a cursor
body: <p>I have this code:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.apod_eso2);  
  
      File f = new File(Environment.getExternalStorageDirectory() + 
          "/Database.sqlite"); 
      CursorFactory factory = null;   
      db =SQLiteDatabase.openDatabase(f.toString(),
          factory,SQLiteDatabase.NO_LOCALIZED_COLLATORS );
  
      ListView list=(ListView)findViewById(R.id.restaurantsApod);  
      KtiriaId=getIntent().getStringExtra(PrevIntent.ID_EXTRA);
      model=DbFileApodEso.getAllEntos(KtiriaId,db);
  
  
      startManagingCursor(model);
      //  
      adapter=new RestaurantAdapter(model);
      list.setAdapter(adapter);
      list.setOnItemClickListener(onListClick);  
  }
  </code></pre>
  
  <p>and the java file i get the cursor is:</p>
  
  <pre><code>public class DbFileApodEso {
  
      private static String TABLE_NAME="TempApodeiEn";
      private static String[] FROM = { "_id","name", "monthPaid",
          "fValue","gotPaid", };
  
      static Cursor getAllEntos(String id,SQLiteDatabase db) {
  
      String[] args={id,"0"};
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
      db.execSQL("CREATE TABLE " + TABLE_NAME + 
          "(_id INTEGER PRIMARY KEY  NOT NULL ,old_id integer " +
          " id1 INTEGER, id2 INTEGER, SNumber DOUBLE, name TEXT, gotPaid INTEGER, 
          monthPaid DATETIME, hmerej DATETIME, user TEXT,tMemo text, 
          GotThere INTEGER)");
  
      db.execSQL("INSERT INTO TempApodeiEn (old_id,eponimo, 
          monthPaid,iddiamerisma,fValue,gotPaid) " +
          "select _id,name,monthPaid,id2,fValue,
          gotPaid from ApodeiEn WHERE id2=? and gotPaid=?", args);
  
      return(db.query(TABLE_NAME, FROM, "id2=?  and gotPaid=?", args, null,
          null, null));
     }
  }
  </code></pre>
  
  <p>i noticed that it takes three seconds to execute: model=DbFileApodEso.getAllEntos(KtiriaId,db)
  So i'd like to show a progressbar to the user to understand that something is happening, How can i do this?
  Thanks for help</p>
  
  <p>I followed the instructions from Shardul and the code is like this:</p>
  
  <pre><code>    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.apod_eso2); 
  
      //DEFINING A NEW THREAD WHICH WOULD DO SOME WORK AND THEN DISMISS THE DIALOG 
      Thread workThread=new Thread(new Runnable(){
  
          @Override
          public void run() {
           //@ albertsmus :call your getAllEntos() here!
           File f = new File(Environment.getExternalStorageDirectory()+"/Eisprakseis.sqlite"); 
        CursorFactory factory = null; 
  
        db =SQLiteDatabase.openDatabase(f.toString(), factory,SQLiteDatabase.NO_LOCALIZED_COLLATORS );
  
        ListView list=(ListView)findViewById(R.id.restaurantsApod);
        KtiriaId=getIntent().getStringExtra(DiamEso.ID_EXTRA);
        EidosApod=getIntent().getStringExtra(DiamEso.ID_Eidos);
        String comment;   // The generated insult.
        model=DbFileApodEso.getAllEntos(KtiriaId,db);
  
        startManagingCursor(model);
        //  
        adapter=new RestaurantAdapter(model);
        list.setAdapter(adapter);
        list.setOnItemClickListener(onListClick);
  
              someTimeConsumingWork(5000);
              //ONLY ONE THREAD CAN HANDLE UI, INCLUDES DISSMISSAL OF
              //PROGRESS DIALOG. runOnUiThread WILL DO ITS MAGIC HERE!
              runOnUiThread(new Runnable(){
  
                  @Override
                  public void run() {
                      mProgressDialog.dismiss();
                      Toast.makeText(ApodEsoListaSec.this, "Work done!", Toast.LENGTH_LONG).show();
                  }
  
              });
          }
  
      });
      workThread.start();
  
      mProgressDialog=ProgressDialog.show(this, "Work Notify!", "Working hard, Phew!");
  }
  
   private void someTimeConsumingWork(long milisToWork){
       SystemClock.sleep(milisToWork);
   }
  </code></pre>
  
  <p>but i eventually get the error  ERROR/AndroidRuntime(6230): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
  why is that? 
  And as i try to debug the error i realized that the error comes up when i call: adapter=new RestaurantAdapter(model);
  Any suggestion?</p>