У меня есть окно реселлера внутри диалогового окна с предупреждением, оно работало, и вдруг первые 6 элементов (первый кеш) имеют пустые текстовые просмотры, когда я прокручиваю оставшуюся нагрузку в порядке. Я проверил, связано ли это с методом on bind, удалив settext () для textview, но даже текст по умолчанию стирается для первых 6 элементов.
Мой адаптер:
public class LogAdapter extends RecyclerView.Adapter<LogAdapter.LogViewHolder> {
private List<Date> logList;
private Context context;
private List<String> activityList;
private RecyclerView recList;
public LogAdapter(List<Date> logList, Context context, List<String> activityList) {
this.logList = logList;
this.context = context;
this.activityList = activityList;
}
@Override
public void onAttachedToRecyclerView(RecyclerView rec){
super.onAttachedToRecyclerView(rec);
this.recList = rec;
}
@Override
public int getItemCount() {
return logList.size();
}
@Override
public void onBindViewHolder(LogViewHolder logViewHolder, final int i) {
Date ci = logList.get(i);
SimpleDateFormat localDateFormat = new SimpleDateFormat("HH");
SimpleDateFormat localTime = new SimpleDateFormat("dd");
String day = ordinal(Integer.parseInt(localTime.format(ci)));
String time = localDateFormat.format(ci);
logViewHolder.viewDate.setText(day + " " + time + ":00 - "+ (Integer.parseInt(time)+1) + ":00");
logViewHolder.setTime(ci);
logViewHolder.save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SaveItem(i, view);
}
});
}
public void SaveItem(int i, View v){
LogViewHolder holder = (LogViewHolder)recList.findViewHolderForAdapterPosition(i);
Realm realm = Realm.getDefaultInstance();
Date date = holder.getTime();
String activity = holder.spinner.getSelectedItem().toString();
realm.beginTransaction();
HourLog log = realm.createObject(HourLog.class);
log.setHour(date);
log.setActivity(realm.where(Activity.class).equalTo("Name",activity).findFirst());
realm.commitTransaction();
logList.remove(i);
notifyItemRemoved(i);
notifyItemRangeChanged(i, logList.size());
}
public String ordinal(int i) {
String[] suffixes = new String[] { "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" };
switch (i % 100) {
case 11:
case 12:
case 13:
return i + "th";
default:
return i + suffixes[i % 10];
}
}
@Override
public LogViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.
from(viewGroup.getContext()).
inflate(R.layout.log_time, viewGroup, false);
return new LogViewHolder(itemView, activityList, context);
}
public static class LogViewHolder extends RecyclerView.ViewHolder {
protected TextView viewDate;
protected Spinner spinner;
protected TextView save;
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
protected Date time;
public LogViewHolder(View v, List<String> cats, Context context) {
super(v);
spinner = v.findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(v.getResources().getColor(R.color.md_white_1000), PorterDuff.Mode.SRC_ATOP);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
R.layout.spinner_item, cats);
spinner.setAdapter(adapter);
viewDate = v.findViewById(R.id.viewDate);
save = v.findViewById(R.id.saveButton);
}
}
}
Пункт утилизации:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@color/colorAccent"
android:orientation="vertical"
android:padding="20dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/viewDate"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="15:00"
android:textColor="@android:color/white"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/saveButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|end"
android:clickable="true"
android:text="Save"
android:textColor="@color/TextHighlight"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/viewDate"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintStart_toEndOf="@+id/textView17"
app:layout_constraintTop_toBottomOf="@+id/billable"
app:layout_constraintVertical_bias="0.019" />
</LinearLayout>