我有一个RecyclerView,我通过检测RecyclerView的结束从我的数据库中加载10到10个项目。
我的问题:装载物品后,当我滚动时,RecyclerView会在1-2秒内冻结。
我认为问题来自每个项目中的ImageView。
每次加载后,最后一个列表会添加到适配器,如下所示:arrayAdapter.list.addAll(questions);
然后arrayAdapter.notifyDataSetChanged();
我的adpater:
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final Question question = list.get(position);
holder.tvOwner.setText("Question posée par " + question.ownerUsername);
holder.tvQuestion.setText(question.question);
if (question.image != null) {
holder.questionImage.setImageBitmap(question.image);
holder.questionImage.setVisibility(View.VISIBLE);
holder.questionImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NavigationMenu nav = (NavigationMenu) context;
nav.showPictureFullScreen(question.image);
}
});
} else {
holder.questionImage.setImageBitmap(null);
holder.questionImage.setVisibility(View.GONE);
}
答案 0 :(得分:0)
感谢Pavan
public class SetImageBitmap extends AsyncTask<Void, Void, Bitmap> {
Question q;
ImageView iv;
public SetImageBitmap(Question q, ImageView iv) {
this.q = q;
this.iv = iv;
}
@Override
protected Bitmap doInBackground(Void... params) {
return q.image;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
iv.setImageBitmap(bitmap);
iv.setVisibility(View.VISIBLE);
}
}