getView being called several times

0

I'm creating an Android app and I came across a problem, I created an adapter to populate the items on my screen, but the getView method is being called several times when I select the product so repeating the details several times, when in fact it should be called only one, below are minimal snippets for an understanding of the problem.

XMl where it contains the items

<RelativeLayout
    android:id="@+id/laydadosprodutos"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="7dp" >

    <TextView
        android:id="@+id/txtDetaCodigoProduto"
        style="@style/detaProdutos" />

    <TextView
        android:id="@+id/txtDetaDescricao"
        style="@style/detaProdutos"
        android:layout_below="@+id/txtDetaCodigoProduto" />

    <TextView
        android:id="@+id/txtDetaCodigoGrupo"
        style="@style/detaProdutos"
        android:layout_below="@+id/txtDetaDescricao" />

    <TextView
        android:id="@+id/txtDetaPreco"
        style="@style/detaProdutos"
        android:layout_below="@+id/txtDetaCodigoGrupo" />

    <TextView
        android:id="@+id/txtQtdeDispProd"
        style="@style/detaProdutos"
        android:layout_below="@+id/txtDetaPreco" />

    <ImageView
        android:id="@+id/imageProduto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignLeft="@+id/txtQtdeDispProd"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="false"
        android:layout_alignWithParentIfMissing="false"
        android:layout_below="@+id/txtQtdeDispProd"
        android:layout_centerInParent="false"
        android:layout_centerVertical="false" />
</RelativeLayout>

Adapter

public class AdapterDetalheProdutosListView extends BaseAdapter
 {
private LayoutInflater                  mInflater;
private GruposProdutoDetalhesActivity   context;
private String[]                        filepath;
private String                          filename;
private Produto                         produto;
File                                    file;
private String                          caminhoImagem;

public AdapterDetalheProdutosListView(GruposProdutoDetalhesActivity context, String[] fpath, String fname, Produto produto)
{
    this.produto = produto;
    filepath = fpath;
    filename = fname;
    this.mInflater = LayoutInflater.from(context);
    this.context = context;
}

@Override
public int getCount()
{

    return filepath.length;
}

@Override
public Object getItem(int position)
{

    return position;
}

@Override
public long getItemId(int position)
{

    return position;
}
//METODO SENDO CHAMADO MAIS DE UMA VEZ
@Override
public View getView(int position, View view, ViewGroup parent)
{
    Locale brasil = new Locale("pt", "BR");
    DecimalFormat decimalFormat = new java.text.DecimalFormat("#######0.0000", new DecimalFormatSymbols(brasil));
    decimalFormat.setParseBigDecimal(true);
    decimalFormat.setDecimalSeparatorAlwaysShown(true);
    decimalFormat.setMinimumFractionDigits(4);

    view = mInflater.inflate(R.layout.itens_produtos_detalhes, null);

    ((TextView) view.findViewById(R.id.txtDetaCodigoProduto)).setText("Código:     " + produto.getCodigo());
    ((TextView) view.findViewById(R.id.txtDetaDescricao)).setText("Descricao:  " + produto.getDescricao());
    ((TextView) view.findViewById(R.id.txtDetaCodigoGrupo)).setText("Grupo:      " + produto.getCodigoGrupo());
    ((TextView) view.findViewById(R.id.txtDetaPreco)).setText("Preço:   R$ " + decimalFormat.format(produto.getPreco()));
    ((TextView) view.findViewById(R.id.txtQtdeDispProd)).setText("Estoque: " + produto.getQtdeEstoque());

    for (int i = 0; i < filepath.length; i++)
    {           
        if (filepath[i].endsWith(filename))
        {
            caminhoImagem = filepath[i];
        }
    }

    ImageView image = (ImageView) view.findViewById(R.id.imageProduto);
    Bitmap bmp = BitmapFactory.decodeFile(caminhoImagem);       
    image.setImageBitmap(bmp);


    return view;
}

Fragment of my activity that arrow the adapter

if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
    {
        Toast.makeText(this, "Erro, SDCARD Não Encontrado!", Toast.LENGTH_LONG).show();
    } else
    {

        file = new File(Environment.getExternalStorageDirectory() + File.separator + "imagem");
        file.mkdirs();
    }

    if (file.isDirectory())
    {
        listFile = file.listFiles();

        listcaminhoImagens = new String[listFile.length];

        listNomeImagens = new String[listFile.length];

        for (int i = 0; i < listFile.length; i++)
        {
            listcaminhoImagens[i] = listFile[i].getAbsolutePath();

            listNomeImagens[i] = listFile[i].getName();

            produto.getCodigo().contains(listNomeImagens[i]);

            nomeImagem = listNomeImagens[i];
        }
    }

    adapterDetalheProdutosListView = new AdapterDetalheProdutosListView(this, listcaminhoImagens, nomeImagem, produto);

    listView = (ListView) findViewById(R.id.listaDetalheProdutos);

    listView.setAdapter(adapterDetalheProdutosListView);

    listView.setCacheColorHint(Color.TRANSPARENT);
    
asked by anonymous 26.05.2015 / 20:59

0 answers