cuốn sách gpt4 ai đã làm

Nhiều đồng hồ đếm ngược trong RecyclerView nhấp nháy khi cuộn

In lại Tác giả: Taklimakan Thời gian cập nhật: 2023-11-02 07:55:09 30 4
mua khóa gpt4 Nike

Tôi đã triển khai đồng hồ đếm ngược cho từng mục của RecyclerView trong Hoạt động phân đoạn. Đồng hồ đếm ngược hiển thị thời gian còn lại cho đến khi hết hạn. Đồng hồ đếm ngược hoạt động tốt nhưng bắt đầu nhấp nháy khi cuộn lên. Đã tìm kiếm rất nhiều nhưng không nhận được trích dẫn tốt. Có ai có thể giúp tôi được không?

Đây là bộ chuyển đổi RecyclerView của tôi

lớp công khai MyOfferAdapter mở rộng RecyclerView.Adapter{
riêng tư cuối cùng Bối cảnh mContext;
cuối cùng riêng tư LayoutInflater mLayoutInflater;
riêng tư ArrayList mItems = new ArrayList<>();
Trình tải hình ảnh riêng tư mImageLoader;
imageURL chuỗi riêng tư;
riêng tư Xem mView;
Chuỗi riêng mUserEmail;

công khai MyOfferAdapter(Ngữ cảnh bối cảnh) {
mContext = bối cảnh;
mLayoutInflater = LayoutInflater.from(ngữ cảnh);
VolleySingleton mVolley = VolleySingleton.getInstance(mContext);
mImageLoader = mVolley.getImageLoader();
}


public void addItems(ArrayList items,String userEmail) {
int count = mItems.size();
mItems.addAll(item);
mUserEmail = email người dùng;
thông báoItemRangeChanged(count, items.size());
}


@Ghi đè
công khai FeedViewHolder onCreateViewHolder(ViewGroup cha, int viewType) {
mView = mLayoutInflater.inflate(R.layout.my_feed_item_layout, parent, false);
trả về FeedViewHolder mới (mView);
}

@Ghi đè
public void onBindViewHolder(người giữ FeedViewHolder cuối cùng, vị trí int cuối cùng) {
Holder.desc.setText(mItems.get(position).getDescription());//thay thế bằng tiêu đề
holder.scratchDes.setText(mItems.get(position).getScratchDescription());

bộ đếm thời gian dài = mItems.get(position).getTimerExpiryTimeStamp();
Ngày hôm nay = Ngày mới();
thời gian dài cuối cùng = hôm nay.getTime();
thời gian hết hạn dài = bộ đếm thời gian - currentTime;


CountDownTimer mới (thời gian hết hạn, 500) {
public void onTick(dài millisUntilFinished) {
giây dài = millisUntilFinished/1000;
phút dài = giây/60;
giờ dài = phút/60;
ngày dài = giờ/24;
Chuỗi thời gian = ngày+" "+"ngày" +" :" +giờ % 24 + ://: + phút % 60 + ://" + giây % 60;
Holder.timerValueTimeStamp.setText(thời gian);
}

khoảng trống công khai trênFinish() {
Holder.timerValueTimeStamp.setText("Hết giờ!");
}
}.bắt đầu();

}

@Ghi đè
công khai int getItemCount() {
trả về mItems.size();
}

lớp tĩnh công khai FeedViewHolder mở rộng RecyclerView.ViewHolder {
Mô tả TextView;
TextView đầuDes;
Bộ đếm thời gian TextViewValueTimeStamp;
Nguồn cấp dữ liệu ImageViewImage;
CardView mCv;

FeedViewHolder công khai(Xem itemView) {
siêu(itemView);
mCv = (CardView) itemView.findViewById(R.id.cv_fil);
desc = (TextView) itemView.findViewById(R.id.desc_tv_fil);
FeedImage = (ImageView) itemView.findViewById(R.id.feed_iv_fil);
ScratchDes = (TextView) itemView.findViewById(R.id.tv_scratch_description);
timeValueTimeStamp = (TextView) itemView.findViewById(R.id.tv_timer_value_time_stamp);

}

}

Đây là tệp xml tôi đang sử dụng trong bộ chuyển đổi


xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">


xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cv_fil"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/card_margin"
android:layout_rabity="center"
ứng dụng:cardUseCompatPadding="true"
ứng dụng:cardElevation="4dp"
android:độ cao="6dp">


android:layout_width="match_parent"
android:layout_height="match_parent">


android:id="@+id/feed_iv_fil"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:tint="@color/grey_tint_color" />


android:id="@+id/tv_scratch_description"
style="@style/ListItemText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:trọng lực="trung tâm"
android:text="giày casul"
android:fontFamily="sans-serif-light"
android:padding="10dp" />



android:id="@+id/tv_timer_value_time_stamp"
style="@style/CardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>


android:id="@+id/desc_tv_fil"
style="@style/VendorNameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/feed_iv_fil"
android:textColor="#3f3e3f"
android:padding="10dp"
/>





Đây là ảnh chụp màn hình RecyclerView của tôi nhập mô tả hình ảnh ở đây

câu trả lời hay nhất

Câu hỏi rất đơn giản.

RecyclerView Tái sử dụng các chủ sở hữu và cập nhật dữ liệu trong đó mỗi khi liên kết được gọi.

Vì mỗi khi dữ liệu nào đó bị ràng buộc (liên kết), một Đếm NgượcHẹn Giờ, do đó bạn sẽ có nhiều bộ hẹn giờ cập nhật giống nhau ViewHolder.

Điều tốt nhất ở đây là di chuyển FeedViewHolder TRONG Đếm NgượcHẹn Giờ Để tham khảo, hãy hủy dữ liệu trước khi liên kết dữ liệu đó (nếu đã bắt đầu) và lên lịch lại theo thời lượng mong muốn.

public void onBindViewHolder(người giữ FeedViewHolder cuối cùng, vị trí int cuối cùng) {
...
if (holder.timer != null) {
chủ.timer.cancel();
}
Holder.timer = new CountDownTimer(expiryTime, 500) {
...
}.bắt đầu();
}

lớp tĩnh công khai FeedViewHolder mở rộng RecyclerView.ViewHolder {
...
Đồng hồ đếm ngược;

FeedViewHolder công khai(Xem itemView) {
...
}
}

Bằng cách này, bạn sẽ hủy bộ hẹn giờ trước khi bắt đầu bộ hẹn giờ khác ViewHolder của bất kỳ trường hợp hẹn giờ hiện tại nào.

Về android - Nhiều đồng hồ đếm ngược trong RecyclerView nhấp nháy trong khi cuộn, chúng tôi đã tìm thấy một câu hỏi tương tự trên Stack Overflow: https://stackoverflow.com/questions/38890863/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress