我使用了firebase的recyclerview和list,我试图测试位置1,2,3中每个位置开始经过的位置中的值,但随后位置值突然恢复为0并从数据中获取文本值已使用的项目。我的Log.i positionAll_打印正在循环播放,看起来像: 0,1,2,3,0,1,2,3
public class StudiumRecyclerAdapter extends RecyclerView.Adapter<StudiumRecyclerAdapter.ViewHolder> {
/*region fields*/
private ArrayList<Stadium> stadiumsList;
private RecycleViewClicListener listener;
private float timeinHoures , rate ;
private MainActivity activity;
private final String TAG = this.getClass().getName();
public StudiumRecyclerAdapter(ArrayList<Stadium> stadiumsList, RecycleViewClicListener listener, MainActivity activity) {
this.stadiumsList = stadiumsList;
this.listener = listener;
this.timeinHoures = time.getTimeInHoures();
this.activity = activity;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.stadium_item_row, parent,false);
StudiumRecyclerAdapter.ViewHolder viewHolder = new StudiumRecyclerAdapter.ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder,int position){
holder.bind(position);
}
@Override
public int getItemCount() {
return stadiumsList.size();
}
/*end metods*/
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private ConstraintLayout not_offer_layout;
private FrameLayout offer_layout;
private TextView studiomName, offer_stadium_name, offer_val_txtV;
private TextView avalibleTextView, offer_available_txt;
private CircleImageView imageView, offer_statium_imageV;
private RatingBar ratingBar, offer_statdium_ratingBar;
private FrameLayout callButton, offer_callButton;
private ImageView giftImage, offer_giftImg;
private TextView s_nike_name_xml, offer_stadium_place;
private ProgressBar row_img_progress;
public ViewHolder(View itemView){
super(itemView);
not_offer_layout = itemView.findViewById(R.id.not_offer_layout_id);
studiomName = itemView.findViewById(R.id.s_name_xml);
imageView = itemView.findViewById(R.id.circleImageView);
avalibleTextView = itemView.findViewById(R.id.s_avaliblity_xml);
ratingBar = itemView.findViewById(R.id.appCompatRatingBar);
s_nike_name_xml = itemView.findViewById(R.id.s_nike_name_xml);
giftImage = itemView.findViewById(R.id.gift_image_xml);
row_img_progress = itemView.findViewById(R.id.row_img_progress);
// ----------------------------------- // -------------------
offer_layout = itemView.findViewById(R.id.offer_item_parent);
offer_available_txt = itemView.findViewById(R.id.offer_s_avaliblity_xml);
offer_stadium_name = itemView.findViewById(R.id.offer_s_name_xml);
offer_statium_imageV = itemView.findViewById(R.id.offer_circleImageView);
offer_stadium_place = itemView.findViewById(R.id.offer_s_nike_name_xml);
offer_statdium_ratingBar = itemView.findViewById(R.id.offer_appCompatRatingBar);
offer_giftImg = itemView.findViewById(R.id.offer_gift_image_xml);
offer_val_txtV = itemView.findViewById(R.id.offer_val_txtV_id);
}
String _rate = "" ;
public void bind(final int position){
String key = stadiumsList.get(position).getKey();
itemView.setOnClickListener(this);
Stadium stadium = stadiumsList.get(position);
// rate = stadium.getRate();
Log.i("positionAll__ :","" +position);
Log.i("rateAll__2 :", "" + stadiumsList.get(position).getRate());
// if(stadium){
// } else {
ratingBar.setRating(stadium.getRate());
if (stadium.getGiftFrom() != null) {
Log.i("YY", "Yess");
//offer_layout.setVisibility(View.VISIBLE);
not_offer_layout.setVisibility(View.VISIBLE);
offer_stadium_name.setText(stadium.getName());
offer_stadium_place.setText(stadium.getAreaName());
offer_statdium_ratingBar.setRating(stadium.getRate());
// For Stadium Logo Image ........................//
String temp = stadiumsList.get(position).getLogoLink();
Picasso.with(activity).load(temp).fit().into(imageView);
if (stadium.getTimeFrom() <= timeinHoures && timeinHoures <= stadium.getTimeTo()) {
avalibleTextView.setText(R.string.avilable);
} else avalibleTextView.setText(R.string.notavlible);
callButton = itemView.findViewById(R.id.call_button);
callButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
activity.call(position);
}
});
offer_val_txtV.setText(stadium.getGiftValue());
offer_val_txtV.append("% off");
ratingBar.setRating(stadium.getRate());
} else {
Log.i("YY", "Noo");
offer_layout.setVisibility(View.GONE);
not_offer_layout.setVisibility(View.VISIBLE);
studiomName.setText(stadium.getName());
s_nike_name_xml.setText(stadium.getAreaName());
String temp = stadiumsList.get(position).getLogoLink();
// For Stadium Logo Image
Picasso.with(activity).load(temp).error(R.drawable.avatar2).into(imageView, new Callback() {
@Override
public void onSuccess() {
row_img_progress.setVisibility(View.GONE);
}
@Override
public void onError() {
}
});
DrawableRequestBuilder<String> thumbnail = Glide.with(activity).load(temp);
try {
Glide.with(activity.getBaseContext()).load(temp).thumbnail(thumbnail).into(imageView);
} catch(Exception e) {
e.printStackTrace();
}
if(stadium.getTimeFrom() <= timeinHoures && timeinHoures <= stadium.getTimeTo()) {
offer_available_txt.setText(R.string.avilable);
} else offer_available_txt.setText(R.string.notavlible);
callButton = itemView.findViewById(R.id.call_button);
callButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
activity.call(position);
}
});
}
Log.i(TAG,stadium.getKey());
Log.i(TAG,stadium.getName());
Log.i(TAG,stadium.getAreaName());
// Log.i("RATSS:----- ", String.valueOf(stadium.getRate()));
}
@Override
public void onClick(View view) {
listener.OnItemClicListener(getAdapterPosition(), stadiumsList.get(getAdapterPosition()), stadiumsList.get(getAdapterPosition()).getIsFree_booking());
}
}
public void setData(ArrayList<Stadium> stadiumsList) {
this.stadiumsList = stadiumsList;
StudiumRecyclerAdapter.this.notifyDataSetChanged();
}
public interface RecycleViewClicListener {
void OnItemClicListener(int position, Stadium stadium_item, String online_book);
}
}