2013-01-07 89 views
0

我有一個progressDialog。 progressDialog中的微調器必須旋轉,並且不應允許用戶執行任何操作。但是微調不能正常工作。它正在凍結,並進入下一個活動。你能幫我解決這個問題嗎?Android - Spinner不旋轉。 Spinner凍結

public void onClick(View v) { 
    // TODO Auto-generated method stub 
    switch (v.getId()){ 
    case R.id.bNewTicket:  
     // custom dialog 
     LayoutInflater li = LayoutInflater.from(context); 
     final View promptsView = li.inflate(R.layout.homepagedialognewticket, null); 
     alertDialogBuilder = new AlertDialog.Builder(context); 
     alertDialogBuilder.setView(promptsView); 

     // set dialog message 
     alertDialogBuilder.setPositiveButton("Go", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
        EditText etTableNumber,etGuestCount; 
        etTableNumber = (EditText) promptsView.findViewById(R.id.etTableNumber); 
        etGuestCount = (EditText) promptsView.findViewById(R.id.etGuestCount); 
        tableNumber = etTableNumber.getText().toString(); 
        guestCount = etGuestCount.getText().toString(); 
        if (tableNumber.isEmpty() || guestCount.isEmpty()) { 
         Dialog d = new Dialog(context); 
         d.setTitle("Alert "); 
         TextView tv = new TextView(context); 
         tv.setText("Table # and Guest # are mandatory "); 
         d.setContentView(tv); 
         d.show(); 
        } else{ 
         dialog.cancel(); 
         runDialog(); 
         } 
       } 
       }) 
       .setNegativeButton("Back",new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
       dialog.cancel(); 
       } 
       }); 

     AlertDialog alertDialog = alertDialogBuilder.create(); 
     alertDialog.show(); 
     break; 
    }  
} 

private void createNewTicket() { 
     try { 

      Terminal terminal; 
      terminal = PosClient.getTerminal(85); 
      Ticket ticket = PosClient.createTicket(Integer.valueOf(tableNumber), Integer.valueOf(guestCount), terminal, ((User) basket.getSerializable("user"))); 
      Intent i = new Intent(HomePage.this,NewTicket.class); 
      basket.putSerializable("ticket", ticket); 
      i.putExtras(basket); 
      startActivity(i); 
     } catch (ClientProtocolException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

private void runDialog() 
    { 
     progressDialog = ProgressDialog.show(this, "Please wait...." , "Menu is loading"); 

     progressDialog.setCancelable(true); 
       new Thread(new Runnable(){ 
      public void run(){ 

      createNewTicket(); 
       progressDialog.dismiss(); 
      } 
     }).start(); 
    } 
+1

在你的runDialog()中,你正在運行什麼後臺進程。你似乎一開始就會解散它。 – Kanth

+0

Appu,我編輯了代碼.. – user1822729

+0

試着把這個progressDialog.setCancelable(true);在runDialog()方法的第一行之後。 – Kanth

回答

0

將createNewTicket函數更改爲異步任務。

在您的代碼中,所有任務都在主線程上運行。僅當主線程停止執行時,佈局更改纔會生效。