URL의 이미지를 표시해야하는 애플리케이션을 작성 중입니다. 이제 내가 100 개의 이미지를 보여줘야한다고 가정 해 보겠습니다. 하나씩 그리고 각각의 사진을 인터넷에서 다운로드해야합니다.안드로이드가 갤러리에서 이미지를 인터넷에서 다운로드해야합니다.
갤러리보기를 사용하여 이미지를 표시하지만 문제는 URL을 getView
으로 전달하면 100 개의 이미지를 모두 다운로드하기 시작합니다 (비동기 작업에서만 가능함). 그러나 100 개의 이미지를 다운로드하면 시스템 속도가 느려집니다. . 제가 성취하고자하는 것은, 제가 올바르게 움직일 때, 제 프로그램은 URL을 골라 인터넷에서 다운로드해야합니다. 내가 사용하려고 시도했다 : 지금 여기에 문제가 즉시 활동이 시스템 아래
@cyngus를 느리게 GalleyList
에 존재하는 모든 URL에 대한로드로 getview
라고한다
public class ViewImage extends Activity {
private String albumID;
private ArrayList<MediaBO>galleryList;
private Context context;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.localgallery);
this.context = this;
Intent intent = getIntent();
Bundle extras = intent.getExtras();
albumID = extras.getString("albumID");
int position = extras.getInt("position"); //position of the image selected
DataBaseOperation dataBaseOperation = new DataBaseOperation(this);
galleryList = dataBaseOperation.queryAllPhoto(albumID); //this returns the list of Photos needs to be shown.it has the URL of the photos
Gallery g = (Gallery) findViewById(R.id.localGallery);
g.setAdapter(new ImageAdapter(this));
g.setSelection(position);
}
public class ImageAdapter extends BaseAdapter{
private Context mContext;
int mGalleryItemBackground;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount(){
return galleryList.size();
}
public Object getItem(int position){
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent){
ImageView i = new ImageView(mContext);
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.localgallery, null);
}
String url = galleryList.get(position).getUrl();
DOWNLOAD()//download the photo using Async Task
v = i;
return v;
}
}
}
Executor e = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
당신에 의해 제안 답 ..하지만 지금은 이것을 사용하는 방법을 잘 ..
나는 집행자 객체를 생성
그러나 호출이를 사용하는 방법을 찾을 수 없습니다 메신저 내 비동기 작업 (BitmapDownloaderTask)
BitmapDownloaderTask task = new BitmapDownloaderTask(con,showDialog,i,path);
task.execute(url,null,null);
내 Asyn 작업이
private class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> {
}
인터넷에서 이미지를 다운로드하고 진행률 막대를 사용하여 gridview에 추가하려면 여기 URL을 따르십시오. http://stackoverflow.com/questions/13415804/android-progress-not-working-accordingly/13416436#comment18333882_13416436 – sai