1
Hello, I read the firebase records and insert an array of objects. The Json class has only business fields and does not have the key field. To delete a record I evaluate that the Best approach would be to change the Json class and insert the key field. Is this the best approach? Thank you.
//I wish to delete the record in this method
listviewCompras.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
// TODO Auto-generated method stub
Log.v("long clicked","pos: " + pos);
return true;
}
})
;
// Code retrieving database data.
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
//habilitando o botao pata evitsr dula entras
buttonSave.setEnabled(true);
ParcelaCartao parcela = new ParcelaCartao();
ArrayList<ParcelaCartao> array = new ArrayList<>();
for (DataSnapshot childSnapshot : snapshot.getChildren())
{
parcela = childSnapshot.getValue(ParcelaCartao.class);
array.add(parcela);
}
monta_listview(array);
Class Parcelcartao
import com.google.firebase.database.*;
import java.util.*;
import java.text.*;
/**
* Created by Belal on 2/23/2016.
*/
//@JsonIgnoreProperties
@IgnoreExtraProperties
public class ParcelaCartao
{
private String descricao;
private long parcelas;
private double valor;
private String datacompra;
private String dataultparcela;
public ParcelaCartao(String descricao, long parcelas ,double valor, String datacompra, String dataultparcela)
{
setDescricao(descricao);
setParcelas(parcelas);
setValor(valor);
setDatacompra(datacompra);
setDataultparcela(dataultparcela);
}
public ParcelaCartao() {
/*Blank default constructor essential for Firebase*/
}
public void setParcelas(long parcelas)
{
this.parcelas = parcelas;
}
public long getParcelas()
{
return parcelas;
}
public String getDescricao()
{
return descricao;
}
public void setDescricao(String descricao)
{
this.descricao = descricao;
}
public double getValor()
{
return valor;
}
public void setValor(double valor)
{
this.valor = valor;
}
public String getDatacompra()
{
return datacompra;
}
public void setDatacompra(String data_compra)
{
this.datacompra = data_compra;
}
public String getDataultparcela()
{
return dataultparcela;
}
public void setDataultparcela(String datault_parcela)
{
this.dataultparcela = datault_parcela;
}
@Override
public String toString() {
return "Compra: " + descricao +
"\n num_parcelas: " + parcelas + " valor: " + valor +
"\n data compra: " + datacompra +
"\n data ult parcela: " + dataultparcela;
}
}
could put a part of the code to better understand your problem
– Vinicius Shiguemori
Hello entered the class. Note that it does not have the key field.
– UltraSeven
I don’t know what the structure of your project looks like, but maybe the code of the screen where the delete method is
– Costamilam
Hello entered the methods of data recovery and deletion.
– UltraSeven