1

我有一个进度对话框。progressDialog 中的微调器必须旋转,它不应该允许用户做任何事情。但是微调器无法正常工作。它被冻结并进入下一个活动。你能帮我解决这个问题吗?

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

1 回答 1

0

将 createNewTicket 函数更改为异步任务。

在您的代码中,所有任务都在主线程上运行。只有在主线程停止执行时,布局更改才会生效。

于 2013-01-07T09:36:57.327 回答