我遇到問題時,我從我的SD卡加載圖像,並顯示他們在我的列表視圖。他們最初加載罰款,但是當我開始向上和向下滾動的圖片讓所有mized起來,不具有相應的列表項加載列表視圖圖像滾動滾動
這裏是我的適配器,我做的一切
@Override
public void bindView(final View view,final Context context,final Cursor cursor){
final int id = cursor.getInt(0);;
final QuickContactBadge image = (QuickContactBadge)view.findViewById(R.id.quickContactBadge1);
image.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(!fromGame){
bowlerID = id;
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
}
}
});
String uri = cursor.getString(3);
if(uri != null){
image.setImageResource(R.drawable.ic_contact_picture);
new LoadImage().execute(new Object[]{uri,image});
}else{
}
TextView first = (TextView)view.findViewById(R.id.bListTextView);
TextView last = (TextView)view.findViewById(R.id.bListTextView2);
first.setText(cursor.getString(1));
last.setText(cursor.getString(2));
}
去圖像我AsyncTask
我給認爲該圖像將顯示和圖像
public class LoadImage extends AsyncTask<Object,Void,Object[]>{
@Override
protected Object[] doInBackground(Object... params) {
String u = (String) params[0];
InputStream input=null;
try {
input = getActivity().getContentResolver().openInputStream(Uri.parse(u));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
Bitmap og = BitmapFactory.decodeStream(input,null,options);
int height = options.outHeight;
int width = options.outWidth;
BitmapFactory.decodeResource(getResources(), R.drawable.ic_contact_picture, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
float scaledHeight = ((float)imageHeight)/height;
float scaledWidth = ((float)imageWidth)/width;
Matrix matrix = new Matrix();
matrix.postScale(scaledWidth, scaledHeight);
Bitmap resize = Bitmap.createBitmap(og, 0, 0, width, height, matrix, true);
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
return new Object[] {resize,params[1]};
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
@Override
public void onPostExecute(Object[] params){
Bitmap resizedImage = (Bitmap)params[0];
QuickContactBadge image = (QuickContactBadge) params[1];
image.setImageBitmap(resizedImage);
}
}
我猜測它是與HANDELING在AsyncTask
圖像的URI,但我怎麼解決?
你是什麼意思? – Siddharth 2014-01-17 09:38:05
downvote是不必要的,它不難理解我的意思是imageview上的默認圖像將被替換 – tyczj 2014-01-17 14:45:26
請閱讀常見問題解答。逆轉downvote,並upvoted,因爲它幫助我解決了我的問題。謝謝。 – Siddharth 2014-01-18 03:55:33