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:
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 methodToString()
?– Enzo Tiezzi
To tell you the truth I don’t even have this Tostring method()
– Emerson Moraes
String k : data in for tu ta setando all fields with the value of k... so the fields will exit repeated
– Pedro Rangel
what exactly you want to show?
– Enzo Tiezzi
in your case, always has the value of k
– Enzo Tiezzi
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.
– Pedro Rangel
show how you did the "data" class in String k : data.
– Pedro Rangel
better explaining which class belongs to the data variable? show how you implemented this class in your question would be a good one.
– Pedro Rangel
@Pedrorangel the data is all I’m searching for from my php file, which contains all the fields I need...
– Emerson Moraes
@Enzotiezzi how would I do not always set k? I can not let repeat everything...
– Emerson Moraes
@Pedrorangel said there, but now that you’ve posted all the code, let’s take a look
– Enzo Tiezzi
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
– Emerson Moraes
the data are coming in what order? are all sequential within data[] ?? need to know how is the vector given after obtaining the values.
– Enzo Tiezzi
Yes, name, address and so on...
– Emerson Moraes