1
scrollView
을 설치하려고하는데 여기에 Grid layout
이 있으며 rating bars
이 적습니다. 이 버튼을 클릭/터치하면 avarege 값이 외부의 Rating Bar
최종본으로 전송됩니다.Android 스튜디오 - RatingBar setOnTouchListener가 제대로 작동하지 않습니다.
그러나 모든 것이 작동하지만 각 값을 보내기 위해 각 ratingbar
을 두 번 클릭/터치해야합니다.
어떤 아이디어가 이런 이유입니까? 예상대로 내가 (한 번의 클릭에/터치)를 scrollView
에서 외부 rating bars
작업을 grid layout
를 이동하면
Layout 내가 평가 표시 줄에서 값을 보내는 데 사용하고
코드는 다음과 같습니다
Valutazione[0].setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onClickRate1();
return false;
}
});
Valutazione[1].setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onClickRate1();
return false;
}
});
Valutazione[2].setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onClickRate1();
return false;
}
});
....
public void onClickRate1()
{
RatingBar Valutazione[] =
{(RatingBar) findViewById(R.id.ratingBar1), (RatingBar) findViewById(R.id.ratingBar2),
(RatingBar) findViewById(R.id.ratingBar3), (RatingBar) findViewById(R.id.ratingBar4),
(RatingBar) findViewById(R.id.ratingBar5), (RatingBar) findViewById(R.id.ratingBar6),
(RatingBar) findViewById(R.id.ratingBar7), (RatingBar) findViewById(R.id.ratingBar8),
(RatingBar) findViewById(R.id.ratingBar9), (RatingBar) findViewById(R.id.ratingBar10)
};
RatingBar rateTot =(RatingBar) findViewById(R.id.ratingBartot);
float Valore[]={0,1,2,3,4,5,6,7,8,9, 10};
Valore[0]=0;Valore[1]=0;
Valore[2]=0;Valore[3]=0;
Valore[4]=0;Valore[5]=0;
Valore[6]=0;Valore[7]=0;
Valore[8]=0;Valore[9]=0;
Valore[10]=0;
int j=0, divisore=0;
TextView finalResult = (TextView) findViewById(R.id.textrate);
while(j<=9) {
Valore[j] = Valutazione[j].getRating();
if(Valore[j] > 0) divisore++;
j++;
}
Valore[10] = (Valore[0] + Valore[1] + Valore[2] + Valore[3] + Valore[4] + Valore[5] + Valore[6] + Valore[7] + Valore[8] + Valore[9])/divisore;
totalRating(rateTot, Valore[10], finalResult);
}
private void totalRating(RatingBar totalBar, float valoreTotale, TextView totalText) {
totalBar.setRating(valoreTotale);
}