2
我有了另一個Recyclerview
在其LIST_ITEM一個Recyclerview
(指孩子Recyclerview
內部父Recyclerview
)項目自動
我的孩子Recyclerview
包含在其list_items ratingbar
。
當我在我的ratingbar
我的孩子單擊Recyclerview
自動滾動(例如:5 ratingbar
點擊,它的滾動汽車,帶我到第3的RatingBar)
我試圖
1日學嘗試:
我用layoutManager.scrollToPosition(moveToPos);
取決於我的ratingbar
點擊位置
第二學嘗試
rvScore.stopScroll();
還是沒有結果
如果想後的代碼我可以
employeeSurveyViewHolder.rtBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//answerCompleted = answerCompleted + 1;
setRatingClick(v, event, position, employeeSurveyViewHolder);
v.onTouchEvent(event);
return true;
}
});
private void setRatingClick(View v, MotionEvent event, int position, EmployeeViewHolder employeeSurveyViewHolder) {
model = list.get(position);
int stars;
if (event.getAction() == MotionEvent.ACTION_UP) {
float touchPositionX = event.getX();
float width = employeeSurveyViewHolder.rtBar.getWidth();
float starsf = (touchPositionX/width) * 5.0f;
stars = (int) starsf + 1;
if (stars == 5) {
employeeSurveyViewHolder.rtBar.setRating(4);
stars = 4;
} else {
employeeSurveyViewHolder.rtBar.setRating(stars);
}
try {
switch (stars) {
case 1:
employeeSurveyViewHolder.tvRatingStatus.setText("POOR");
model.rating = stars;
if (ratingPos != position) {
answersList.remove(position);
answersList.add(position, "" + model.rating);
answerCompleted = answerCompleted + 1;
ratingPos = position;
} else {
answersList.set(position, "" + model.rating);
}
break;
case 2:
employeeSurveyViewHolder.tvRatingStatus.setText("FAIR");
model.rating = stars;
if (ratingPos != position) {
answersList.remove(position);
answersList.add(position, "" + model.rating);
answerCompleted = answerCompleted + 1;
ratingPos = position;
} else {
answersList.set(position, "" + model.rating);
}
break;
case 3:
employeeSurveyViewHolder.tvRatingStatus.setText("GOOD");
model.rating = stars;
if (ratingPos != position) {
answersList.remove(position);
answersList.add(position, "" + model.rating);
answerCompleted = answerCompleted + 1;
ratingPos = position;
} else {
answersList.set(position, "" + model.rating);
}
break;
case 4:
employeeSurveyViewHolder.tvRatingStatus.setText("EXCELLENT");
model.rating = stars;
if (ratingPos != position) {
answersList.remove(position);
answersList.add(position, "" + model.rating);
answerCompleted = answerCompleted + 1;
ratingPos = position;
} else {
answersList.set(position, "" + model.rating);
}
break;
default:
employeeSurveyViewHolder.rtBar.setRating(0);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d(TAG, "list.size(): = " + list.size());
Log.d(TAG, "answerCompleted: = " + answerCompleted);
Log.d(TAG, "answersList.size(): = " + answersList.size());
if (list.size() == answerCompleted) { // if nos of question is = to nos of answerCompleted
completedListener.isRatingCompleted(true, "" + answersList, position);
//Log.d(TAG, "setCompleted: = true");
} else {
completedListener.isRatingCompleted(false, "" + answersList, position); // just scrolling the recycler view.
//Log.d(TAG, "setCompleted: = false");
}
// Allow parent to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(false);
v.setPressed(false);
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Disallow parent to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
v.setPressed(true);
}
if (event.getAction() == MotionEvent.ACTION_CANCEL) {
v.setPressed(false);
}
}