2012-05-14 4 views
0

Я хочу, чтобы не скрывать прогресс диалога в андроиде после нажатия кнопки, я хочу, чтобы выполнить некоторые операции только при сохранении Dialog появляется, У меня есть следующий код для создания диалога:Как сохранить диалог в андроиде?

public Dialog onCreateDialog(int id){ 
     switch(id){ 
     case 0 : 
      // Alert Dialog 
      return null; 
     case 1: 

      progressDialog = new ProgressDialog(this); 
      progressDialog.setIcon(R.drawable.ic_launcher); 
      progressDialog.setTitle("Play audio file"); 

      progressDialog.setCancelable(false); 
      progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 

    /*  progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"Play", 
        new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface dialog, int which) { 

        Toast.makeText(getBaseContext(),"Hide clicked!",Toast.LENGTH_SHORT).show(); 
       } 
      });*/ 

      progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Close", new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface dialog, int which) { 
        Toast.makeText(getBaseContext(),"Cancel clicked!",Toast.LENGTH_SHORT).show(); 

       } 
      }); 
      progressDialog.setButton("Play", new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface dialog, int which) { 
        Toast.makeText(getBaseContext(),"Cancel clicked!",Toast.LENGTH_SHORT).show(); 

       } 
      }); 
      return progressDialog; 
     } 
     return null; 

    } 
+0

'dialog.dismiss()' –

+0

Прохладный, так что случилось с вашим кодом? – Blundell

ответ

0

я использовал AlertDialog с пользовательским расположением внутри него. Контролируя onClickListeners в пользовательском макете, я могу решить, когда отменить диалог. Я много о Диалог не знаю, но это работает для меня, а также должны работать для вас, хотя я не знаю, можно ли это сделать с ProgressDialog специально

@Override 
    public void openDialog(Context context) { 

     // declare the dialog object 
     AlertDialog.Builder builder; 
     AlertDialog alertDialog = null; 

     // inflate the layout to use inside it 
     View layout = ((Activity)context).getLayoutInflater().inflate(R.layout.list_selector_horizontal,null, false); 

     TextView text = (TextView) layout.findViewById(R.id.list_selector_textView1); 
     text.setText("Select a product:"); 

     // set the dialog to use the layout 
     builder = new AlertDialog.Builder(context); 
     builder.setView(layout);       
     alertDialog = builder.create(); 

     // *important* Set this to false to stop users dismissing the dialog when they tap outside of it 
     alertDialog.setCanceledOnTouchOutside(false); 

     // populate the layout with some more views 
     LinearLayout scrollContainer = (LinearLayout) layout.findViewById(R.id.list_selector_linearLayout2);     
     for(int i = 0;i<products.size();i++){ 
      Product product = products.get(i); 
      View view = product.getView(context); 

      // set the onClickListener for the product view 
      view.setOnClickListener(new ProductListOnClickListener(alertDialog, product, this, v)); 
      view.setPadding(10, 10, 10, 10); 
      scrollContainer.addView(view); 
     } 

     // show the dialog 
     alertDialog.show(); 

    } 

Тогда в onClickListener:

class ProductListOnClickListener implements OnClickListener{ 

     private AlertDialog alertDialog;      
     private Product p; 
     private View view; 
     private boolean dismiss = false; 

     public ProductListOnClickListener(AlertDialog alertDialog, Product p, View view) {    
      this.alertDialog = alertDialog; 
      this.p = p; 
      this.view = view; 
     } 

     @Override 
     public void onClick(View v) { 
      // do whatever 

      if(dismiss){ 
       // dismiss dialog 
       alertDialog.dismiss(); 
      } 
     } 

    } 
Смежные вопросы