0
Hello guys I’m new in Android and I’m with a question of data overwriting in listview that I haven’t been able to find yet. I have a Tabbed with 3 tabs, and when clicking the first time tab the listview appears correctly but when switching tab and returning to Tab from listview it duplicates the data!
public class Tabagendaferramentas extends Fragment{
public static Context context;
//Início código ref. ListView com checkbox
public ListView listViewFerramentas;
public ArrayList<String> arrayListFerramentas=new ArrayList<>();
//Fim código ref. ListView com checkbox
String campoSituacaoAgenda = "ABERTA";
View view;
public TabAgendaFerramentas(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.tabagendaferramentas, container, false);
//Inicio método chama menu tabFerramentas
setHasOptionsMenu(true);
//Fim método chama menu tabFerramentas
//Chamar listar ferramentas
listarFerramentas();
//Fim chamar listar ferramentas
return view;
}
public void listarFerramentas(){
listViewFerramentas = (ListView) view.findViewById(R.id.listview);
listViewFerramentas.setAdapter(null);
List<ModeloFerramentas> modeloferramentas = new FerramentaController(getContext()).listarFerramenta();
for (ModeloFerramentas ferramenta : modeloferramentas) {
int id = ferramenta.getIdFerramenta();
String nomeFerramenta = ferramenta.getNomeFerramenta();
float valorFerramenta = ferramenta.getValorFerramenta();
arrayListFerramentas.add("CÓD: " + id + " FERRAMENTA: " + nomeFerramenta + "\n" + "R$: " + valorFerramenta);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, arrayListFerramentas);
listViewFerramentas.setAdapter(adapter);
}
}
//In the image below I changed tab and went back to tool where duplicated the tools