0
我有一個imageAdapter 這是代碼:的Android適配卡在0位置
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageGalleryAdapter extends BaseAdapter {
private Context mContext;
public String[] imagePaths;
public ImageGalleryAdapter(Context c, String paths) {
mContext = c;
imagePaths = paths.split(";");
}
@Override
public int getCount() {
return imagePaths.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return imagePaths[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.i("IMAGE GALLERY ADAPTER", ""+position);
ImageView imageView = new ImageView(mContext);
imageView.setImageURI(Uri.parse(imagePaths[position]));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}
我不知道爲什麼,但它總是讓我的應用程序沒有響應,所以我嘗試設置Log.i檢查在getView的位置,其結果是位置始終都值= 0,而imagePath.length = 4
爲什麼總是停留在位置= 0
這是日誌:
07-11 18:38:25.310: I/IMAGE GALLERY ADAPTER(32154): **0**
07-11 18:38:25.313: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg addr:0x53c64000, size:65536, fd:59
07-11 18:38:25.316: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg reply:6
07-11 18:38:25.316: W/skia(32154): Use JPEG SW Decoder
07-11 18:38:25.484: I/dalvikvm-heap(32154): Grow heap (frag case) to 29.849MB for 19660816-byte allocation
07-11 18:38:25.726: I/SurfaceTextureClient(32154): [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms
07-11 18:38:25.744: E/MMUMapper(32154): fail to register MVA, unsupported format(0x5)
07-11 18:38:25.746: I/IMAGE GALLERY ADAPTER(32154): **0**
07-11 18:38:25.749: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg addr:0x53c64000, size:65536, fd:60
07-11 18:38:25.751: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg reply:6
07-11 18:38:25.751: W/skia(32154): Use JPEG SW Decoder
07-11 18:38:25.943: I/dalvikvm-heap(32154): Grow heap (frag case) to 48.574MB for 19660816-byte allocation
07-11 18:38:26.191: I/IMAGE GALLERY ADAPTER(32154): **0**
07-11 18:38:26.194: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg addr:0x53c64000, size:65536, fd:60
07-11 18:38:26.195: I/MdpService(32154): [MDP INFO](32154): BpMdpService::parseJpg reply:6
07-11 18:38:26.195: W/skia(32154): Use JPEG SW Decoder
07-11 18:38:26.214: I/dalvikvm-heap(32154): Forcing collection of SoftReferences for 19660816-byte allocation
07-11 18:38:26.243: E/dalvikvm-heap(32154): Out of memory on a 19660816-byte allocation.
請幫忙解決這個
'paths'的價值是什麼?你可以逐步瀏覽或記錄這個值,也可以記錄'imagePaths'的大小。 –
由於內存不足錯誤,您正在強制關閉。看起來它試圖分配19mb。 – Scott