2012-05-22 5 views

답변

1
public class ProgressDialog extends PopupScreen 
    { 
     public ProgressDialog(String waitString) 
     { 
      super(new VerticalFieldManager()); 
      add(new LabelField(waitString,Field.FIELD_HCENTER));//add a string which u want to show for progressing 
     } 
    } 

ProgressDialog progress = new ProgressDialog("Please Wait..."); 
//Add screen to UI 
UiApplication.getUiApplication().pushScreen(progress); 


//Remove screen from UI 
progress.close(); 
0
ProgressBar progressBar = new ProgressBar("Waiting for location update....",50,1000); 

progressBar.start(); // Start progress bar 
progressBar.remove(); //remove progress bar 

의 ProgressBar 스레드

public class ProgressBar extends Thread { 

    Thread thd; 
    private int maximum, timeout; 

    private boolean useful = true; 

    private PopupScreen popup; 

    private int iterations = 0; 

    /** 
    * Object constructor 
    * 
    * @param title 
    *   Text to display on popup area 
    * @param maximum 
    *   Range/width of the gauge field of progress bar 
    * @param timeout 
    *   Milliseconds to pause between updates to progress bar 
    * @see GaugeField 
    * @see Thread 
    * @see PopupScreen 
    */ 

    public ProgressBar(String title, int maximum, int timeout) { 
     this.maximum = maximum; 
     this.timeout = timeout; 


     VerticalFieldManager manager = new VerticalFieldManager(); 

     popup = new PopupScreen(manager); 


     manager.add(new LabelField(title)); 

    } 

    /** 
    * run() method for starting thread 
    */ 

    public void run() { 

     UiApplication.getUiApplication().invokeLater(new Runnable() { 
      public void run() { 
       UiApplication.getUiApplication().pushScreen(popup); 
      } 
     }); 

     int iterations = 0;  

     while (useful) { 
      System.out.println("I m here in while runn "+ useful); 
      try { 
       Thread.sleep(timeout); 
      } catch (Exception e) { 

      } 

      if (++iterations > maximum) 
      { 
       iterations = 1; 
       useful = false; 
       UiApplication.getUiApplication().invokeLater(new Runnable() 
       { 
        public void run() 
        { 
         _locationProvider.reset(); 
         Dialog.alert("Location not found."); 

        } 
       }); 

      } 

      //   gaugeField.setValue(iterations);    
     } 

     if (popup.isDisplayed()) { 
      UiApplication.getUiApplication().invokeLater(new Runnable() { 
       public void run() { 
        UiApplication.getUiApplication().popScreen(popup); 
       } 
      }); 
     } 
    } 

    /** 
    * Method to shutdown the thread and remove the popup screen 
    * 
    */ 

    public synchronized void remove() { 
     useful = false; 
    } 

} 
관련 문제