这是两个按钮:确认率并确定清除率。 我试试这个代码,当我按下按钮"清除"第一次它没问题且清晰可行,但它没有工作,对话框关闭了。 如何在点击清除按钮时更改方法? 提前谢谢。
@Override
protected void populateView(View rootView) throws Exception {
super.populateView(rootView);
voterestaurant.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog d = new Dialog(getActivity());
d.setTitle("Rate it!");
d.setCancelable(false);
d.setContentView(R.layout.pf_frame_rating);
final RatingBar RatingBar = (RatingBar) d.findViewById(R.id.MyratingBar);
final TextView TextRate = (TextView) d
.findViewById(R.id.ratetext);
Button ok = (Button) d.findViewById(R.id.bt_confirm);
TextRate.setVisibility(View.INVISIBLE);
RatingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar,
float rating, boolean fromUser) {
int rate = (int) RatingBar.getRating();
Math.ceil(rate);
// TextRate.setText(String.valueOf(rate));
switch (rate) {
case 0:
TextRate.setText(String.valueOf("Pessimo"));
break;
case 1:
TextRate.setText(String.valueOf("Scarso"));
break;
case 2:
TextRate.setText(String.valueOf("Buono"));
break;
case 3:
TextRate.setText(String
.valueOf("Molto buono"));
break;
case 4:
TextRate.setText(String
.valueOf("Eccellente!"));
break;
}
TextRate.setVisibility(View.VISIBLE);
}
});
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// memorizza valore rating
d.dismiss();
}
});
Button clear = (Button) d.findViewById(R.id.bt_clear);
clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RatingBar.setRating(0F);
RatingBar.setFocusable(true);
d.dismiss();
}
});
d.show();
}
});
答案 0 :(得分:1)
从清除按钮单击侦听器中删除d.dismiss();
此行并检查。