ThAdapter 클래스에 오류가 하나 있습니다. imageView에 이미지를 표시하고 textView에 이미지 이름을 표시하려고하지만 오류가 표시됩니다. 오류가 getView()에 있음을 알고 있지만 변경 방법을 알지 못합니다. 누군가가 나를 도울 수 있습니까 ??android : getView에서 오류가 발생했습니다.
public class Th extends BaseAdapter {
// Context required for performing queries
private final Context mContext;
// Cursor for thumbnails
private final Cursor cursor;
private final int imgId;
private final int imgData;
private final int count;
public Th(Context c) {
this.mContext = c;
// Get list of all images, sorted by last taken first
final String[] projection = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA
};
cursor = mContext.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Images.Media.DATE_TAKEN + " DESC"
);
// Set constants (column indices and image count)
imgId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
imgData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
count = cursor.getCount();
Log.d("ThumbnailAdapter", count + " images found");
}
@Override
public int getCount() {
return count;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
TextView textView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
textView = new TextView(mContext);
} else {
imageView = (ImageView) convertView;
textView = (TextView) convertView;
}
// Move cursor to image position, fetch id, and generate/view thumbnail
cursor.moveToPosition(position);
final Bitmap thumbnail = MediaStore.Images.Thumbnails.getThumbnail(
mContext.getContentResolver(),
cursor.getInt(imgId),
MediaStore.Images.Thumbnails.MICRO_KIND,
null
);
imageView.setImageBitmap(thumbnail);
textView.setText(cursor.getString(imgData));
return imageView;
}
/**
* Get the image path from the given position
* @param position
* @return
*/
public String getImagePath(int position) {
cursor.moveToPosition(position);
return cursor.getString(imgData);
}
오류 게시 ... –