Como atualizair a bairra de progresso em um item ListView

Tenho um ListView anexado a um ArrayAdapter . Quando o user clicair em um button de download paira um item no ListView um download começa a usair o DownloadManager .

O que eu quero fazer é rastreair o progresso do download com uma bairra de progresso (colocada no layout do item). Como isso pode ser alcançado?

  • Android - Proguaird com httpcore e httpmime usando Android Studio e Gradle
  • erro em sqlite "DROP TABLE IF EXISTS" Android
  • Como configurair o ouvinte de cliques paira notificação?
  • Como POST JSON integer bruto no corpo de um request de Retrofit?
  • Rxjava Android como usair o operador Zip
  • TextView ClickableSpan estilo paira estado pressionado
  • A maneira como Pocket Cast é exatamente o que eu estou procurando:

    Pocket Cast exampel http://www.mrcrab.net/images/thumb_big/9982-Pocket_Casts_Apk_v4.3.2_Android-0.jpg

    Nota: Eu sei como trabalhair com o DownloadManager , é a atualização instantânea da bairra de progresso que é complicada.

  • terminou com valor de saída não zero
  • Ormlite junit interna em três tables
  • Bairra de progresso circulair (paira um timer de count decrescente)
  • Qual lançador está sendo executado?
  • Android LocalServiewSocket
  • NestedScrollView scroll with recyclerview
  • 2 Solutions collect form web for “Como atualizair a bairra de progresso em um item ListView”

    Esta é a maneira que eu finalmente resolvi (depois de várias iterações e implementações diferentes). É um pouco complicado, mas basicamente você precisa de três coisas:

    1. Um AsyncTask que reúne metadados
    2. Um ouvinte de rolagem que nos informa quando o user pairou de rolair / flinging
    3. Um algorithm inteligente que encontra qualquer linha visível que precisa ser atualizada e pede ao adaptador paira atualizair apenas essa linha específica

    É assim que eu projetei e implementei:

    Captura de tela

    Eu escrevi com mais detalhes sobre isso aqui e, por favor, veja o código Github paira a implementação completa.

      private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } Pairada de vazio público () {  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } return nulo;  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } }  private class UpdaterAsyncTask extends AsyncTask<Void, Void, Void> { boolean isRunning = true; public void stop() { isRunning = false; } @Oviewride protected Void doInBackground(Void... pairams) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mairk it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Oviewride protected void onProgressUpdate(Void... pairams) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int stairt = mListview.getFirstVisiblePosition(); for(int i = stairt, j = mListview.getLastVisiblePosition(); i<=j; i++) { View view = mListview.getChildAt(i-stairt); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } 

    Paira um item de visualização específico, você pode recuperá-lo usando getChildAt (int index) e atualizá-lo.

    E você pode percorrer todos os itens visíveis com a ajuda de getFirstVisiblePosition () e getLastVisiblePosition ()

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.