2012-02-11 91 views

回答

0

試試這個

use the flag value as reference 


if flag value is true then user click on item then it will play the sound 
else sound wont play and display one dialog that Do you want enable sound with two options yes or no 
      if user click on yes then make flag value as true and item.setText("Voice Disable"); otherwise no action means no changes in flag 
      in your list item click listener write condition as following 
      if(flag==true) 
      { 
       write your logic to play 
      } 

示例代碼禁用聲音

public class app extends UiApplication{ 


    public static void main(String[] args) { 
     new app().enterEventDispatcher(); 
    } 

    public app() { 
     pushScreen(new SampleScreen()); 
    } 
} 
class SampleScreen extends MainScreen 
{ 
    static boolean flag=true; 
    MenuItem item=null; 
    public SampleScreen() { 

//  use the flag value as reference 
//  if flag value is true then user click on item then it will play the sound 
//  else sound wont play and display one dialog that Do you want enable sound with two options yes or no 
//  if user click on yes then make flag value as true and item.setText("Voice Disable"); otherwise no action means no changes in flag 
//  in your list item click listner write condition as following 
//  if(flag==true) 
//  { 
//   write your logic to play 
//  } 



     // you already implement 

     item=new MenuItem("Voice Disable",0,100) { 
      public void run() { 
       if(flag) 
       { 
        flag=false; 
        item.setText("Voice Enable"); 
        UiApplication.getUiApplication().invokeLater(new Runnable() { 
         public void run() { 
          Dialog.inform("Voice Disable succesfully"); 
         } 
        }); 
       }else{ 
        flag=true; 
        item.setText("Voice Disable"); 
        UiApplication.getUiApplication().invokeLater(new Runnable() { 
         public void run() { 
          Dialog.inform("Voice Enable succesfully"); 
         } 
        }); 
       } 

      } 
     }; 
     addMenuItem(item); 

    } 
}