2013-09-26 46 views
0

我有一個自定義對話框,應該在按下android星級評估者控件時啓動,但沒有任何對話框打開。自定義對話框將不會打開

XML的星級評定者:

<RatingBar 
     android:id="@+id/beerRatingBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:numStars="5" 
     android:stepSize="1.0" 
     android:rating="0" 
     style="?android:attr/ratingBarStyleSmall" 
     android:clickable="true" 
     android:onClick="rateDialog" 
     /> 

推出對話框的方法是:

public void rateDialog(View v){ 
     // custom dialog 
     dialog = new Dialog(this); 
     dialog.setContentView(R.layout.rate_stars); 
     dialog.setTitle("Rate this Beer"); 

    } 

再次,單擊小ratebar打開不打開對話框的對話框。

回答

2

嘗試增加dialog.show()

public void rateDialog(View v){ 
    // custom dialog 
    dialog = new Dialog(this); 
    dialog.setContentView(R.layout.rate_stars); 
    dialog.setTitle("Rate this Beer"); 
    dialog.show()   // <-- this guy here 
} 
1

在你的代碼缺少一個電話

dialog.show(); 

然而,建議的方式做自定義對話框是一個DialogFragment