Make two items in a ListView switch position

0

I am creating a button called upload, to make an item in the listview go up, while the one that was above goes down. But I've tried everything and it will not, I do not know if I'm wrong in logic.

But I tried to do it in two ways. The first (Position is the ID of the item I clicked):

 auxtema = tema[posicao-1];
 auxpalavras = palavras[posicao-1];
 auxtempo = tempo[posicao-1];

 lista.remove(posicao-1);

 HashMap<String,String> substituir = new HashMap<String,String>();
 substituir.clear(); 
 substituir.put("tema",auxtema+": "+auxtempo);
 substituir.put("palavras",auxpalavras);
 lista.add(posicao,substituir);

((BaseAdapter) resumo.getAdapter()).notifyDataSetChanged(); 

The second form:

auxtema = tema[posicao];
auxpalavras = palavras[posicao];
auxtempo = tempo[posicao];

auxtema1 = tema[posicao-1];
auxpalavras1 = palavras[posicao-1];
auxtempo1 = tempo[posicao-1];

lista.remove(posicao-1);
lista.remove(posicao);

HashMap<String,String> substituir = new HashMap<String,String>(); 
substituir.put("tema",auxtema+": "+auxtempo);
substituir.put("palavras",auxpalavras); 
lista.add(posicao-1,substituir);

HashMap<String, String> substituir2 = new HashMap<String, String>();
substituir.put("tema",auxtema1+": "+auxtempo1);
substituir.put("palavras",auxpalavras1);
lista.add(posicao,substituir2);

Am I doing something wrong?

    
asked by anonymous 07.02.2014 / 14:23

2 answers

2

Your code is a bit confusing and incomplete (I do not see the list statement) but based on the description of your problem, I imagine you can do the following:

Collections.swap(lista, indice_posicao_item_cima, indice_posicao_item_baixo)

Comment if you still have any questions

    
07.02.2014 / 14:55
1

John Neto does not work?

Object aux = lista.get(posicao-1);
lista.remove(posicao-1);
lista.add(posicao, aux);
    
07.02.2014 / 14:53