0
to learn, I’m trying to create a custom listview, taking values from the bank, created this Metasacvivity where I call the list method
public void listarMetas() {
ArrayList<Meta> values = new ArrayList<>();
Cursor cursor = meuBanco.query("metas", null,null,null,null,null,null);
while (cursor.moveToNext()){
int idMetas = cursor.getInt(cursor.getColumnIndex("id"));
String nomeMeta = cursor.getString(cursor.getColumnIndex("nome"));
String tempo = cursor.getString(cursor.getColumnIndex("hora"));
Meta item = new Meta(idMetas,nomeMeta,tempo);
values.add(new Meta(idMetas,nomeMeta,tempo));
System.out.println("MOVE------:");
System.out.println("ArrayList : " + item.getId() + "======" + item.getNome() + "----" + item.getTempo());
System.out.println("ITEM+++++++++++");
lv_metas = (ListView)findViewById(R.id.lv_metas);
adapter1 = new MetasAdapter(MetasActivity.this,values);
lv_metas.setAdapter(adapter1);
}
And I created Metasadapter:
Meta item = this.getItem(position);
MetasHolder holder = null;
if(convertView == null){
convertView = LayoutInflater.from(this.context).inflate(R.layout.item_list, null);
holder = new MetasHolder();
holder.nomeMeta = (TextView)convertView.findViewById(R.id.tv_nomeCategoria);
holder.tempo = (TextView)convertView.findViewById(R.id.tv_tempo);
convertView.setTag(holder);
} else {
holder = (MetasHolder)convertView.getTag();
}
Meta metas = data.get(position);
holder.nomeMeta.setText(item.getNome());
System.out.println("metas.getNome()======" + item.getNome());
holder.tempo.setText(item.getTempo());
System.out.println("metas.getTempo()======" + item.getTempo());
return convertView;
The problem is that the custom listview is only filled with the last record. It creates lines in the amount and every time I save a value, all the lines in the listview are changed, where I’m missing?