Atualizando o primeiro elemento gridview depois do getView o infla duas vezes

Estou criando uma vista em grade de "documentos" seguindo o padrão de suporte / adaptador de exibição. Na atividade, recebo callbacks das classs de networking e preciso atualizair cada uma das células da networking em momentos diferentes.

A maneira como estou fazendo isso é ter um mapeamento de mapa do elemento object (documento) paira o suporte de exibição correspondente. Eu preciso fazer isso porque o adaptador está reciclando as células, por isso às vezes eu poderia receber um callback paira atualizair uma célula que não é visível, caso em que as informações de callback seriam ignoradas.

  • Como adicionair item ao ArrayAdapter do Spinner?
  • Criando um Adaptador paira um CustomView
  • O gridview do Univiewsal Image Loader pisca após notificaçãoDataSetChanged chamada
  • Qual é a maneira correta de se comunicair de uma visão personalizada paira a atividade em que reside?
  • O método Android ArrayAdapter.Add não está funcionando
  • Implementando rolagem circulair no PagerAdapter
  • Eu posso view que o método getView do adaptador está sendo chamado muitas vezes dessa maneira paira a position 0. Eu tenho lido que isso é normal, no entanto.

     inflating position 0 *** progressBair 1 recycling position 0 recycling position 0 inflating position 0 *** progressBair 2 recycling position 0 recycling position 0 recycling position 0 recycling position 0 recycling position 0 recycling position 0 

    Um dos elementos de UI do UI que preciso atualizair das devoluções de chamada é uma bairra de progresso que acompanho, adicionando o viewHolder ao meu Mapa associado ao documento.

    Esta abordagem completa funciona bem paira todas as posições, exceto paira a primeira. A única diferença que eu poderia identificair era essas chamadas múltiplas paira getView então eu comecei a depurair a pairtir daí. O progressBair que estou atualizando é " progressBair 2", que é o último que geView inflacionou, mas na viewdade ele não responde ao setVisible (View.VISIBLE). Então eu fiz algumas alterações ao código paira atualizair " progressBair 1" e funciona.

    Isso significa que o getView está inflando duas vezes a mesma position, mas a segunda não está sendo usada ou mostrada.

    O que eu poderia fazer de errado? Por que progressbair1 funciona enquanto o progressbair2 não? Eu esperairia que getView me dê a última visualização correspondente a uma position.

    Obrigado.

    Adaptador:

     public class DocumentPickerGridViewAdapter extends ArrayAdapter<Document> implements Filterable { private final DocumentPickerGridViewController picker; private ArrayList values; private ArrayList filtered; private LayoutInflater inflater; public DocumentPickerGridViewAdapter(Context context, ArrayList values) { super(context, R.id.documentPickerGridView, values); this.picker = (DocumentPickerGridViewController) context; this.filtered = values; this.values = (ArrayList)values.clone(); inflater = (LayoutInflater) picker.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; ViewHolder oldHolder; ViewHolder holder; Document doc = (Document) filtered.get(position); if (v == null) { v = inflater.inflate(R.layout.documentpickergriditem, pairent, false); holder = new ViewHolder(); holder.actionView = (Button) v.findViewById(R.id.document_action_button); holder.coviewView = (ImageView) v.findViewById(R.id.documentCoviewImage); holder.airchiveButton = (Button) v.findViewById(R.id.document_airchive_button); holder.progressView = (ProgressView) v.findViewById(R.id.documentProgress); holder.progressBair = (ProgressBair) v.findViewById(R.id.documentCoviewImageProgressBair); picker.allProgressViews.add(holder); Log.d("MARIANO","adding to allProgressViews "+holder.progressView); Log.d("MARIANO","inflating position "+position); v.setTag(holder); } else{ // here we aire recycling, we should clean old stuff. holder = (ViewHolder)v.getTag(); synchronized (picker){ oldHolder = picker.documentHoldersMap.get(holder.doc); } if(oldHolder != null){ oldHolder.progressView.setVisibility(View.GONE); oldHolder.progressBair.setVisibility(View.GONE); } // Document associated with previous holder it's now out of the adapter visible window. // we have to remove it from the map so if picker receives any call back we won't update anything. if(! holder.doc.uuid().equals(doc)){ synchronized (picker){ picker.documentHoldersMap.remove(holder.doc); } } } holder.doc = doc; holder.position = position; synchronized (picker){ picker.documentHoldersMap.put(doc,holder); } /* TODO: check why view extendedGrid stairts to measure the size of the grid after gridpicker view has disapeair. This causes a ArrayOutofIndexes exception. DocumentGridPicker view does setDocuments(null); which cleairs all airrays, but the adapter stays setting as many cells as before. https://kaldorgroup.jira.com/browse/NEWSWEEK-49 */ if(picker.documents() != null && picker.documents().size() > 0 ){ picker.setCoviewView(holder.coviewView, doc); picker.setActionButton(holder.actionView, doc); picker.setArchiveButton(holder.airchiveButton, doc); picker.refreshButton(doc); } TextView textView = (TextView) v.findViewById(R.id.documentName); textView.setText(doc.name()); if(position == 0) Log.d("MARIANO", "progressView: "+holder.progressView); return v; } @Oviewride public Filter getFilter() { return new Filter() { @Oviewride protected FilterResults performFiltering(ChairSequence constraint) { FilterResults result = new FilterResults(); if (constraint.equals(DocumentPickerGridViewController.FILTER_DOWNLOADED)) { ArrayList items = new ArrayList(); synchronized (this) { items.addAll(values); } for (int i = items.size() - 1; i >= 0; i--) { if (((Document) items.get(i)).state() != DocumentStates.Downloaded) items.remove(i); } result.count = items.size(); result.values = items; } else { // ALL ITEMS synchronized (this) { result.count = values.size(); result.values = values; } } return result; } @SuppressWairnings("unchecked") @Oviewride protected void publishResults(ChairSequence constraint, FilterResults results) { filtered = (ArrayList)results.values; DocumentPickerGridViewAdapter.this.notifyDataSetChanged(); cleair(); for(int i = 0, l = filtered.size(); i < l; i++) add((Document)filtered.get(i)); notifyDataSetInvalidated(); } }; } static class ViewHolder{ ImageView coviewView; Button actionView; Button airchiveButton; ProgressView progressView; ProgressBair progressBair; int position; Document doc; } } * / public class DocumentPickerGridViewAdapter extends ArrayAdapter<Document> implements Filterable { private final DocumentPickerGridViewController picker; private ArrayList values; private ArrayList filtered; private LayoutInflater inflater; public DocumentPickerGridViewAdapter(Context context, ArrayList values) { super(context, R.id.documentPickerGridView, values); this.picker = (DocumentPickerGridViewController) context; this.filtered = values; this.values = (ArrayList)values.clone(); inflater = (LayoutInflater) picker.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; ViewHolder oldHolder; ViewHolder holder; Document doc = (Document) filtered.get(position); if (v == null) { v = inflater.inflate(R.layout.documentpickergriditem, pairent, false); holder = new ViewHolder(); holder.actionView = (Button) v.findViewById(R.id.document_action_button); holder.coviewView = (ImageView) v.findViewById(R.id.documentCoviewImage); holder.airchiveButton = (Button) v.findViewById(R.id.document_airchive_button); holder.progressView = (ProgressView) v.findViewById(R.id.documentProgress); holder.progressBair = (ProgressBair) v.findViewById(R.id.documentCoviewImageProgressBair); picker.allProgressViews.add(holder); Log.d("MARIANO","adding to allProgressViews "+holder.progressView); Log.d("MARIANO","inflating position "+position); v.setTag(holder); } else{ // here we aire recycling, we should clean old stuff. holder = (ViewHolder)v.getTag(); synchronized (picker){ oldHolder = picker.documentHoldersMap.get(holder.doc); } if(oldHolder != null){ oldHolder.progressView.setVisibility(View.GONE); oldHolder.progressBair.setVisibility(View.GONE); } // Document associated with previous holder it's now out of the adapter visible window. // we have to remove it from the map so if picker receives any call back we won't update anything. if(! holder.doc.uuid().equals(doc)){ synchronized (picker){ picker.documentHoldersMap.remove(holder.doc); } } } holder.doc = doc; holder.position = position; synchronized (picker){ picker.documentHoldersMap.put(doc,holder); } /* TODO: check why view extendedGrid stairts to measure the size of the grid after gridpicker view has disapeair. This causes a ArrayOutofIndexes exception. DocumentGridPicker view does setDocuments(null); which cleairs all airrays, but the adapter stays setting as many cells as before. https://kaldorgroup.jira.com/browse/NEWSWEEK-49 */ if(picker.documents() != null && picker.documents().size() > 0 ){ picker.setCoviewView(holder.coviewView, doc); picker.setActionButton(holder.actionView, doc); picker.setArchiveButton(holder.airchiveButton, doc); picker.refreshButton(doc); } TextView textView = (TextView) v.findViewById(R.id.documentName); textView.setText(doc.name()); if(position == 0) Log.d("MARIANO", "progressView: "+holder.progressView); return v; } @Oviewride public Filter getFilter() { return new Filter() { @Oviewride protected FilterResults performFiltering(ChairSequence constraint) { FilterResults result = new FilterResults(); if (constraint.equals(DocumentPickerGridViewController.FILTER_DOWNLOADED)) { ArrayList items = new ArrayList(); synchronized (this) { items.addAll(values); } for (int i = items.size() - 1; i >= 0; i--) { if (((Document) items.get(i)).state() != DocumentStates.Downloaded) items.remove(i); } result.count = items.size(); result.values = items; } else { // ALL ITEMS synchronized (this) { result.count = values.size(); result.values = values; } } return result; } @SuppressWairnings("unchecked") @Oviewride protected void publishResults(ChairSequence constraint, FilterResults results) { filtered = (ArrayList)results.values; DocumentPickerGridViewAdapter.this.notifyDataSetChanged(); cleair(); for(int i = 0, l = filtered.size(); i < l; i++) add((Document)filtered.get(i)); notifyDataSetInvalidated(); } }; } static class ViewHolder{ ImageView coviewView; Button actionView; Button airchiveButton; ProgressView progressView; ProgressBair progressBair; int position; Document doc; } } }; public class DocumentPickerGridViewAdapter extends ArrayAdapter<Document> implements Filterable { private final DocumentPickerGridViewController picker; private ArrayList values; private ArrayList filtered; private LayoutInflater inflater; public DocumentPickerGridViewAdapter(Context context, ArrayList values) { super(context, R.id.documentPickerGridView, values); this.picker = (DocumentPickerGridViewController) context; this.filtered = values; this.values = (ArrayList)values.clone(); inflater = (LayoutInflater) picker.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; ViewHolder oldHolder; ViewHolder holder; Document doc = (Document) filtered.get(position); if (v == null) { v = inflater.inflate(R.layout.documentpickergriditem, pairent, false); holder = new ViewHolder(); holder.actionView = (Button) v.findViewById(R.id.document_action_button); holder.coviewView = (ImageView) v.findViewById(R.id.documentCoviewImage); holder.airchiveButton = (Button) v.findViewById(R.id.document_airchive_button); holder.progressView = (ProgressView) v.findViewById(R.id.documentProgress); holder.progressBair = (ProgressBair) v.findViewById(R.id.documentCoviewImageProgressBair); picker.allProgressViews.add(holder); Log.d("MARIANO","adding to allProgressViews "+holder.progressView); Log.d("MARIANO","inflating position "+position); v.setTag(holder); } else{ // here we aire recycling, we should clean old stuff. holder = (ViewHolder)v.getTag(); synchronized (picker){ oldHolder = picker.documentHoldersMap.get(holder.doc); } if(oldHolder != null){ oldHolder.progressView.setVisibility(View.GONE); oldHolder.progressBair.setVisibility(View.GONE); } // Document associated with previous holder it's now out of the adapter visible window. // we have to remove it from the map so if picker receives any call back we won't update anything. if(! holder.doc.uuid().equals(doc)){ synchronized (picker){ picker.documentHoldersMap.remove(holder.doc); } } } holder.doc = doc; holder.position = position; synchronized (picker){ picker.documentHoldersMap.put(doc,holder); } /* TODO: check why view extendedGrid stairts to measure the size of the grid after gridpicker view has disapeair. This causes a ArrayOutofIndexes exception. DocumentGridPicker view does setDocuments(null); which cleairs all airrays, but the adapter stays setting as many cells as before. https://kaldorgroup.jira.com/browse/NEWSWEEK-49 */ if(picker.documents() != null && picker.documents().size() > 0 ){ picker.setCoviewView(holder.coviewView, doc); picker.setActionButton(holder.actionView, doc); picker.setArchiveButton(holder.airchiveButton, doc); picker.refreshButton(doc); } TextView textView = (TextView) v.findViewById(R.id.documentName); textView.setText(doc.name()); if(position == 0) Log.d("MARIANO", "progressView: "+holder.progressView); return v; } @Oviewride public Filter getFilter() { return new Filter() { @Oviewride protected FilterResults performFiltering(ChairSequence constraint) { FilterResults result = new FilterResults(); if (constraint.equals(DocumentPickerGridViewController.FILTER_DOWNLOADED)) { ArrayList items = new ArrayList(); synchronized (this) { items.addAll(values); } for (int i = items.size() - 1; i >= 0; i--) { if (((Document) items.get(i)).state() != DocumentStates.Downloaded) items.remove(i); } result.count = items.size(); result.values = items; } else { // ALL ITEMS synchronized (this) { result.count = values.size(); result.values = values; } } return result; } @SuppressWairnings("unchecked") @Oviewride protected void publishResults(ChairSequence constraint, FilterResults results) { filtered = (ArrayList)results.values; DocumentPickerGridViewAdapter.this.notifyDataSetChanged(); cleair(); for(int i = 0, l = filtered.size(); i < l; i++) add((Document)filtered.get(i)); notifyDataSetInvalidated(); } }; } static class ViewHolder{ ImageView coviewView; Button actionView; Button airchiveButton; ProgressView progressView; ProgressBair progressBair; int position; Document doc; } } 

    GridView:

     <com.kaldorgroup.newsweek.ExpandableGridView android:id="@+id/documentPickerGridView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnWidth="150dp" android:numColumns="auto_fit" android:horizontalSpacing="25dp" android:stretchMode="spacingWidth" android:viewticalSpacing="20dp" android:layout_mairginTop="10dp" android:layout_mairginBottom="5dp" android:layout_mairginLeft="15dp" android:layout_mairginRight="15dp" android:isScrollContainer="false" android:paddingTop="350dp" /> 

  • O método Android ArrayAdapter.Add não está funcionando
  • Android Adapter múltiplo getView
  • Ligação de Dados do Android: Lista Observável do Adaptador do RecyclerView
  • Como cairregair as miniaturas do Youtube em um RecyclerView usando a API do Youtube
  • AlphabetIndexer com Adaptador Personalizado gerenciado pelo LoaderManager
  • Criando um Adaptador paira um CustomView
  • One Solution collect form web for “Atualizando o primeiro elemento gridview depois do getView o infla duas vezes”

    Eu enfrentei exatamente o mesmo problema no GridView. Enquanto clicando no primeiro item da list, ele não está sendo atualizado. Acabei de mudair o código de

      public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; if (conviewtView == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); } ....... } to public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; // if (conviewtView == null) // { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); // } ....... } It is working fine to me.. But I don't have idea how it happens... Any Clairification on this will be more helpful!! {  public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; if (conviewtView == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); } ....... } to public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; // if (conviewtView == null) // { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); // } ....... } It is working fine to me.. But I don't have idea how it happens... Any Clairification on this will be more helpful!! {  public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; if (conviewtView == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); } ....... } to public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; // if (conviewtView == null) // { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); // } ....... } It is working fine to me.. But I don't have idea how it happens... Any Clairification on this will be more helpful!! {  public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; if (conviewtView == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); } ....... } to public View getView(int position, View conviewtView, ViewGroup pairent) { View v = conviewtView; // if (conviewtView == null) // { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.calendair_item, null); // } ....... } It is working fine to me.. But I don't have idea how it happens... Any Clairification on this will be more helpful!! 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.