Loop para fazer upload de imagens da lista, uma por uma
eu querocarregar várias imagens uma por uma, como quando o usuário toca no botão carregar tudo, ele precisa começar com a primeira imagem visível em uma lista, uma vez que a primeira imagem é carregada no servidor e, em seguida, automaticamente, a segunda é carregada, mas após um ou dois segundos e o mesmo para todos imagens disponíveis em uma lista.
Este é o meu código, que me permite carregar uma única imagem: -
Código para fazer upload de imagem única
// btnUpload
holder.uploadImageButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Upload
startUpload(position);
}
});
estou usandoabaixo código, mas éupload / sincronização todas as imagens ao mesmo tempo, minha média junto, como eu tenho500 imagens em uma lista para a suacarregando todos os 500 juntos e, como resultado, estou recebendo erro quando a conexão à Internet cai e muitas vezes não obtendo o status exato das imagens carregadas!
private SparseBooleanArray flags = new SparseBooleanArray();
// At onClick, set all the flags to indicate that some data needs to be synced
ImageButton buttonUploadAll = (ImageButton) findViewById(R.id.sync_btn);
buttonUploadAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
for(int position=0; position<listView.getAdapter().getCount(); position++)
{
flags.put(position, true);
}
// Calling this would ensure a call to getView() on every
// visible child of the listview. That is where we will check if
// the data is to be synced and displayed or not
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
}
});
@Override
// In getView of the listview's adapter
public View getView(int position, View convertView, ViewGroup parent) {
// If this item is to be synced
if(flags.get(position)) {
startUpload();
// Mark as synced
flags.put(position, false);
}
// Rest of the method that draws the view....
}
é por isso que eu querocarregar várias imagens uma por uma (em uma fila)