在Recyclerview中使用超过9个评级栏时,它显示出奇怪的值。即;当我对评级栏进行评级时,其他评级栏也会更改其值。 这是我的代码
public class SurveyAdapter : RecyclerView.Adapter
{
const String TAG = "QUICK_ADAPTER";
public override RecyclerView.ViewHolder OnCreateViewHolder (ViewGroup parent, int viewType)
{
View v = LayoutInflater.From (parent.Context).Inflate (Resource.Layout.survey_items, parent, false);
return new ViewHolder (v);
}
public override void OnBindViewHolder (RecyclerView.ViewHolder holder, int position)
{
var vh = holder as ViewHolder;
vh.ratingBar.Rating = 0;
vh.ratingBar.RatingBarChange += (o, e) => {
Log.Error (TAG, "Rating change pos:" + position + " & value :" + (int)vh.ratingBar.Rating + "\n");
};
}
public override int ItemCount {
get { return 20; }
}
public class ViewHolder : RecyclerView.ViewHolder
{
public RatingBar ratingBar{ get; private set; }
public ViewHolder (View itemView) : base (itemView)
{
itemView.FindViewById<RatingBar> (Resource.Id.Rating);
}
}
}
在更改评级栏中的评分时,我会得到这样的结果 假设我将评级栏评级为1位
评级变化pos:1&amp;价值:4
评级变化pos:8&amp;价值:4
评级变化pos:12&amp;价值:4
评级变化pos:14&amp;价值:4
答案 0 :(得分:3)
请试试这个,
如果您使用ListView
- 请覆盖以下方法。
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
如果您使用RecycyclerView
- 仅覆盖getItemViewType
方法。
@Override
public int getItemViewType(int position) {
return position;
}