Problem in the organization of the data of a Listview - Basedapter

Asked

Viewed 59 times

0

I’m having a little problem organizing the personal data of an external Mysql database. Like, I created a Infopeoplesdapter class inheriting from Basedapter where I pick up name, address, neighborhood, zip code, phone and remarks. I played on listview the following way:

List<InfoPessoais> dadosPessoais = new ArrayList<InfoPessoais>();
    InfoPessoais ip = new InfoPessoais();

    for (String k : dados) {
        ip = new InfoPessoais();
        ip.setNome(k);
        ip.setEndereco(k);
        ip.setBairro(k);
        ip.setCep(k);
        ip.setTelefone(k);
        ip.setObs(k);
        dadosPessoais.add(ip);
    }
    lvInformacoesPessoais.setAdapter(new InfoPessoaisAdapter(this, dadosPessoais));

The problem is that at the time of showing on the screen of my device, it shows the name repeatedly for all fields, hence the next field repeats again and so on... it gets all wrong as in the image below:

inserir a descrição da imagem aqui

dice:

try{
        respostaRetornada = ConexaoHttpClient.executaHttpPost(url, parametrosPost);
        String resposta = respostaRetornada.toString();
        resposta = resposta.replaceAll("\\s+", "");
        Log.i("Informações", "Informações: "+resposta);

        char separador = '#';
        int contadados = 0;

        for (int i=0; i < resposta.length(); i++){
            if (separador == resposta.charAt(i)){
                contadados++;
                dados = new String[contadados];
            }
        }

        char caracterLido = resposta.charAt(0);
        String nome = "";

        for (int i=0; caracterLido != '^'; i++){
            caracterLido = resposta.charAt(i);
            Log.i("Chars", "Chars do Paciente"+caracterLido);

            if (caracterLido != '#'){
                if (caracterLido == '*'){
                    nome = nome + " ";
                }else
                nome+= (char) caracterLido;

            }else{
                Log.i("Nome", "Nome: "+nome);
                dados[posicao] =""+ nome;
                Log.i("Nome posição ["+posicao+"]", ""+dados[posicao]);
                posicao = posicao + 1;
                nome = "";
            }
        }
        Log.i("Fim", "Fim do for");

    }catch(Exception erro){
        Toast.makeText(getBaseContext(), "Erro: "+erro, Toast.LENGTH_LONG).show();
    }
  • in your class InfoPessoais was made the @Override of the method ToString()?

  • To tell you the truth I don’t even have this Tostring method()

  • String k : data in for tu ta setando all fields with the value of k... so the fields will exit repeated

  • what exactly you want to show?

  • in your case, always has the value of k

  • you have to do something like this... ip.setName(data.getitem(i).getName()); this getitem is just an example to be able to item in position i.

  • show how you did the "data" class in String k : data.

  • better explaining which class belongs to the data variable? show how you implemented this class in your question would be a good one.

  • @Pedrorangel the data is all I’m searching for from my php file, which contains all the fields I need...

  • @Enzotiezzi how would I do not always set k? I can not let repeat everything...

  • @Pedrorangel said there, but now that you’ve posted all the code, let’s take a look

  • Yes, but by the variable data, I can’t pull any of that... it’s just a String[] where I stored all the php data

  • the data are coming in what order? are all sequential within data[] ?? need to know how is the vector given after obtaining the values.

  • Yes, name, address and so on...

Show 9 more comments

1 answer

1


Instead of making the following code :

for (String k : dados) {
    ip = new InfoPessoais();
    ip.setNome(k);
    ip.setEndereco(k);
    ip.setBairro(k);
    ip.setCep(k);
    ip.setTelefone(k);
    ip.setObs(k);
    dadosPessoais.add(ip);
}

Do the following:

int i = 0;
while(i < dados.length)
{
    ip = new InfoPessoais();
    ip.setNome(dados[i++]);
    ip.setEndereco(dados[i++]);
    ip.setBairro(dados[i++]);
    ip.setCep(dados[i++]);
    ip.setTelefone(dados[i++]);
    ip.setObs(dados[i++]);
    dadosPessoais.add(ip);
}

This is very impractical to do, but for now to solve your problem, this is enough.

  • hot, worked perfectly... Obrigado...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.