2013-09-27 32 views
0

我在這我想傳遞一個浮動的對話框,如下所示:如何將值傳遞給android對話框?

public void rateDialog(View v){ 
     // custom dialog 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
// Add the buttons 
     builder.setPositiveButton("save", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       // User clicked OK button 
      } 
     }); 
     builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       // User cancelled the dialog 
      } 
     }); 
    // Set other dialog properties 

     // Create the AlertDialog 
     builder.setTitle("Rate this Beer"); 
     builder.setView(getLayoutInflater().inflate(R.layout.rate_stars, null)); 
     AlertDialog dialog = builder.create(); 

     RatingBar ratingBar = (RatingBar) this.findViewById(R.id.beerRatingBar); 
     float stars = ratingBar.getRating(); 


     dialog.show(stars); 

    // Create the AlertDialog 



    } 

這實際上是可能的,如果是怎樣?

+0

如何使用DialogFragment?你的目標是低於API 11嗎? –

回答

0

你可以聲明它作爲最後:

public void rateDialog(View v){ 
    // custom dialog 

    final Float value = 1; 

} 

並在對話框中使用它。

0

你可以粘貼你的rate_stars.xml,它看起來如何。

如果您正在使用RatingBar,那麼您可以在java文件中設置評分,然後調用show方法。

如果你不使用RatingBar,試試它會很容易設置評級。

相關問題