안드로이드에 처음 생겼습니다. 가로보기에서 이미지 재활용과 관련된 몇 가지 문제가 있습니다. 나는이 링크 "How to dynamic unload images from gallery?"을 참조로 시도했다. 안드로이드의 HorizontalView에서 ImageView 재활용하기
이
내 mainActivity.java입니다 : ContentResolver cr=getContentResolver();
phones=cr.query(android.provider.Contacts.People.CONTENT_URI,null, android.provider.Contacts.People._ID + "=?", new String[]{String.valueOf(""+pVal[i])},null);
Log.d("Curdsr="," "+phones);
while (phones.moveToNext()) {
String name=phones.getString(phones.getColumnIndex(android.provider.Contacts.People.DISPLAY_NAME));
String phoneNumber=phones.getString(phones.getColumnIndex(android.provider.Contacts.People.NUMBER));
int PhotoId=phones.getColumnIndex(android.provider.Contacts.People._ID);
Log.d("PathVal=",""+PhotoId);
Log.d("P-Name=",name);
long phId=phones.getLong(PhotoId);
//String phoneNumber=getPhoneNumber(phId);
//getPhoto(phId);
Bitmap photoVal=getPhoto(phId);
Log.d("PhoyId=",phId+"");
// RETRIEVE THE CONTACT PHOTO AS A BITMAP
Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, phId);
Bitmap bitmap = People.loadContactPhoto(getApplicationContext(), uri, R.drawable.no_image, null);
// SET IT HERE IN THE IMAGEVIEW
// profile.setImageBitmap(bitmap);
ContactBean objContact = new ContactBean();
objContact.setId(PhotoId);
objContact.setName(name);
objContact.setpId(phId);
objContact.setPhoneNo(phoneNumber);
objContact.setImage(phId);
objContact.setPicture(bitmap);
list.add(objContact);
}
}
phones.close();
objAdapter = new ContanctAdapter(
this, R.layout.alluser_row, list);
//listView.setAdapter(objAdapter);
listview1.setAdapter(objAdapter);
와 여기 내 어댑터 클래스는 "ContactsAdapter.java"
공용 클래스 ContanctAdapter가 {
private Activity activity;
private List<ContactBean> items;
private int row;
private ContactBean objBean;
public ContanctAdapter(Activity act, int row, List<ContactBean> items) {
super(act, row, items);
//super(act, R.layout.alluser_row, items);
this.activity = act;
this.row = row;
this.items = items;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ImageView Parcel=new ImageView(this.getContext());
System.out.println("getview:"+position+" "+convertView);
View view = convertView;
ViewHolder holder;
if (convertView == null) {
Log.d("CustomArrayAdapter", "New");
//LayoutInflater inflater=activity.getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(row,parent, false);
Log.d("View Value",view.toString());
holder = new ViewHolder();
holder.Imagess=(ImageView) view.findViewById(R.id.imageView1);
holder.tvname=(TextView) view.findViewById(R.id.tvname);
//holder.tvname=(TextView)view.findViewById(R.id.tvnames);
//tvName=(TextView)findViewById(R.id.tvname);
// holder.Imagess.setVisibility(View.VISIBLE);
view.setTag(holder);
} else {
Log.d("pathChange","hi");
holder = (ViewHolder) view.getTag();
}
objBean = items.get(position);
holder.tvname.setText(objBean.getName());
holder.tvname.bringToFront();
Log.d("Names", objBean.getName());
Log.d("thisItem","This Item is Index " + position + " " + view.toString() + " " + Integer.toHexString(System.identityHashCode(view)));
holder.Imagess.setImageBitmap(objBean.getPicture());
if((position-4)>=0){
items.get(position-4).getPicture().recycle();
}
else{
Log.d("before",""+position);
}
return view;
}
public class ViewHolder {
public TextView tvname, tvPhoneNo;
public ImageView Imagess;
}
}
ArrayAdapter와 확장으로 이름에뮬레이터에서 실행할 때 오류 로그가 다음과 같이 표시됩니다.
07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : java.lang.RuntimeException : Canvas : 재생 된 비트 맵을 사용하려고 시도했습니다. [email protected] 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.graphics.Canvas.throwIfRecycled (Canvas.java:1026) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.graphics.Canvas.drawBitmap (Canvas .java : 1127) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.graphics.drawable.BitmapDrawable.draw (BitmapDrawable.java:393) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.widget.ImageView.onDraw (ImageView.java:985) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java) : 13712) 07-12 09 : 12 : 44.383 : E/AndroidRuntim e (5245) : android.view.View.draw (View.java:13596) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java : 2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13715) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13596) 07 -12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java:2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android. view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13594) 07-12 09 : 12 : 4 4.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java:2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13715) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13596) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java : 2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13715) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13596) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java:2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : at android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13715) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13596) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view. ViewGroup.drawChild (ViewGroup.java:2928) 07-12 09:12:44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13594) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java:2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java : 13594) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.drawChild (ViewGroup.java:2928) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewGroup.dispatchDraw (ViewGroup.java:2797) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.View.draw (View.java:13715) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.widget.FrameLayout.draw (FrameLayout.java:467) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : at com.android.internal.policy.impl.PhoneWindow $ DecorView.draw (PhoneWindow.java:2211) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewRootImpl.drawSoftware (ViewRootImpl. 자바 : 2281) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewRootImpl.draw (ViewRootImpl.java:2177) 07-12 09 : 12 : 44.383 : E/AndroidRuntime 5245) : android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2045) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1854) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:989) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.ViewRootImpl $ TraversalRunnable.run (ViewRootImpl.java:4351) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.Choreographer $ CallbackRecord.run (Choreographer.java:749) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.Choreographer.doCallbacks (Choreographer.java:562) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.view.Choreographer.doFrame (Choreographer.java:532) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : at android.view.Choreographer $ FrameDisplayEventReceiver.run (Choreographer.java:735) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.os.Handler.handleCallback (Handler.java:725) 07 -12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : android.os.Handler.dispatchMessage (Handler.ja 이메일 : AndroidRuntime (5245) : android.os.Looper.loop (Looper.java:137) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (va : 92) 07-12 09 : 12 : 44.383 5245) : android.app.ActivityThread.main (ActivityThread.java:5041) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : java.lang.reflect.Method.invokeNative (기본 메소드) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : java.lang.reflect.Method.invoke (Method.java:511) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:793) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : com.android.internal.os.ZygoteInit.main에서 (ZygoteInit.java:560) 07-12 09 : 12 : 44.383 : E/AndroidRuntime (5245) : at dalvik.system.NativeStart.main (기본 메소드)
제발 도와주세요 .. 미리 감사드립니다.
어딘가에 bitmap.recycle()을 호출해야합니다. 방법. 이 메서드는 비트 맵을 더 이상 사용하지 않는 경우에만 호출해야합니다. – Rajeev
감사 Rajeev .. 내 문제에 관한 몇 가지 코드를 게시 할 수 있습니다. – sheik
'if ((position-4)> = 0) { items.get (position-4) .getPicture(). 재활용(); } ' 가능합니다. (position-4)는 무엇을하고 있으며 왜 그 비트 맵을 재활용해야합니까? – Rajeev