시스템이 목록보기에서 올바른 위치의보기를로드 할 때까지 시스템이 재생보기 인 것으로 보이므로 몇 초 동안 이미지와 텍스트가 중복됩니다. 누구든지 도와 줄 수 있습니까?flinging 및 스크롤하는 동안 몇 초 동안 잘못된보기를 표시하는 목록보기
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
Log.d("position",""+position);
if(v==null){
LayoutInflater inflater = LayoutInflater.from(mContext);
v = inflater.inflate(R.layout.layout_appinfo, null);
holder = new ViewHolder();
holder.ivAppIcon = (ImageView)v.findViewById(R.id.ivIconApp);
holder.tvAppName = (TextView)v.findViewById(R.id.tvNameApp);
holder.progress = (ProgressBar)v.findViewById(R.id.progress_spinner);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.ivAppIcon.setImageDrawable(null);
holder.tvAppName.setText(null);
holder.progress.setVisibility(View.VISIBLE);
holder.ivAppIcon.setVisibility(View.GONE);
// Using an AsyncTask to load the slow images in a background thread
new AsyncTask<ViewHolder, Void, Drawable>() {
private ViewHolder v;
private ResolveInfo entry = (ResolveInfo) mListAppInfo.get(position);
@Override
protected Drawable doInBackground(ViewHolder... params) {
v = params[0];
return entry.loadIcon(mPackManager);
}
@Override
protected void onPostExecute(Drawable result) {
super.onPostExecute(result);
// If this item hasn't been recycled already, hide the
// progress and set and show the image
v.progress.setVisibility(View.GONE);
v.ivAppIcon.setVisibility(View.VISIBLE);
v.ivAppIcon.setImageDrawable(result);
v.tvAppName.setText(entry.loadLabel(mPackManager));
}
}.execute(holder);
return v;
}
static class ViewHolder {
TextView tvAppName;
ImageView ivAppIcon;
ProgressBar progress;
//int position;
}
마치 몇 초 동안 위치를 잘못 설정 한 것과 같습니다.
getView는 asyncTask를 넣을 적절한 위치가 아니며 독립적으로 실행하고 데이터를 사용할 수있는 경우 뷰를 업데이트하십시오. 어댑터에서 notifydatasetchanged를 호출하면 getView에서만 이미지를 사용할 수 있는지 확인하십시오. 그렇지 않으면 기본 이미지가 표시됩니다. 당신은 DiskLruCache를 사용하여 작은 버전의 이미지를 유지할 수 있습니다. Google의 클래스는 프레임 워크의 일부가 아니지만 빠르게 작동합니다. 여기에 그냥 볼 때마다 이미지를 다운로드 –
http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html – Raghunandan