gpt4 book ai didi

android - 阻止 RatingBar 上的某些评级

转载 作者:行者123 更新时间:2023-11-29 17:26:42 27 4
gpt4 key购买 nike

评分栏有一个 OnRatingBarChangeListener,它仅在评分已被用户更改时才起作用。我希望当用户点击评级栏进行 3 星评级时,RatingBar 提示不允许 3 星评级的 Toast

最佳答案

这段代码会帮助你。

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating);
RatingBar ratingBar;
ratingBar = (RatingBar)findViewById(R.id.ratingBar);
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

@Override
public void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser) {
// TODO Auto-generated method stub
if(rating == 3){
Toast.makeText(getApplicationContext(), "3 star rating is not allowed.", Toast.LENGTH_LONG).show();
ratingBar.setRating(0);
}
}
});
}

关于android - 阻止 RatingBar 上的某些评级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34378247/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com