gpt4 book ai didi

android - 评级条 : same rating twice

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:15 27 4
gpt4 key购买 nike

我的问题是,当我再次对相同的值进行评分时,它不会响应第二次..这意味着当我第一次评分为“4”时,我不能将其评分为“4”第二次..只有当我评价其他值而不是'4'时它才会响应。

这是我尝试过的(我的代码中需要 getRatingBar 的操作)。

public class InteractiveRatingBarActivity extends Activity implements
OnRatingBarChangeListener {
RatingBar getRatingBar;
RatingBar setRatingBar;
TextView countText;
int count;
float curRate;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

findViewsById();

setRatingBar.setRating(curRate);//overall rating
getRatingBar.setOnRatingBarChangeListener(this);// ratingbar for user action.

}

private void findViewsById() {
getRatingBar = (RatingBar) findViewById(R.id.getRating);
setRatingBar = (RatingBar) findViewById(R.id.setRating);
countText = (TextView) findViewById(R.id.countText);
}


public void onRatingChanged(RatingBar rateBar, float rating,
boolean fromUser) {
DecimalFormat decimalFormat = new DecimalFormat("#.#");
curRate = Float.valueOf(decimalFormat.format((curRate * count + rating)
/ ++count));
Toast.makeText(InteractiveRatingBarActivity.this,
"New Rating: " + curRate, Toast.LENGTH_SHORT).show();
setRatingBar.setRating(curRate);
countText.setText(count + " Ratings");
}


}

提前致谢

最佳答案

发生这种情况是因为您有 OnRatingChange(如果它保持不变,您的评级不会改变,因此不会调用此方法)。

您可以开发一个 OnTouchListen:

ratingBar.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
float touchPositionX = event.getX();
float width = ratingBar.getWidth();
float starsf = (touchPositionX / width) * 5.0f;
int stars = (int) starsf + 1;

DecimalFormat decimalFormat = new DecimalFormat("#.#");
curRate = Float.valueOf(decimalFormat.format((curRate
* count + starsf)
/ ++count));
Toast.makeText(InteractiveRatingBarActivity.this,
"New Rating: " + curRate, Toast.LENGTH_SHORT)
.show();
setRatingBar.setRating(curRate);
countText.setText(count + " Ratings");
v.setPressed(false);
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
v.setPressed(true);
}

if (event.getAction() == MotionEvent.ACTION_CANCEL) {
v.setPressed(false);
}

return true;
}
});

关于android - 评级条 : same rating twice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18716519/

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