cursor.moveToFirst return FALSE at the second lap in the while loop. First line is inserted, instead when i insert another line, program don't work.Thanks This is my methods:
private void addDdtRow(String codiceMagazzino, String dataCreazione, String codiceLotto, Double quantita) { // TODO Auto-generated method stub boolean check = false; double qta = quantita; Cursor cursor = dbm.queryInventarioMag("CODICE_MAGAZZINO=?", new String[] { codiceMagazzino }); if (cursor != null) { int i_codMag = cursor.getColumnIndex(DatabaseStrings.CAMPO_COD_MAG); int i_riga = cursor.getColumnIndex(DatabaseStrings.CAMPO_RIGA); int i_dataCr = cursor .getColumnIndex(DatabaseStrings.CAMPO_DATA_CREAZIONE); int i_codLotto = cursor .getColumnIndex(DatabaseStrings.CAMPO_COD_LOTTO); int i_qta = cursor.getColumnIndex(DatabaseStrings.CAMPO_QTA);
int i = 0;
int pos = -1;
boolean hasNext = cursor.moveToFirst();
if (hasNext) {
while (hasNext) {
pos = cursor.getPosition();
i = cursor.getInt(i_riga);
if (cursor.getString(i_codMag).equals(codiceMagazzino)
&& cursor.getString(i_codLotto).equals(codiceLotto)) {
check = true;
hasNext = false;
} else {
indexRiga = i + 1;
hasNext = cursor.moveToNext();
}
}
if (check) { // se match codLotto && match codArt
cursor.moveToPosition(pos);
indexRiga = i;
qta = (qta + cursor.getInt(i_qta));
}
} else {
indexRiga = 0;
}
if (check) {
dbm.updateRigaMagaz(DatabaseStrings.TBL_MAGAZZINO, qta,
"CODICE_MAGAZZINO=? AND " + "RIGA=?", new String[] {
codiceMagazzino, String.valueOf(indexRiga) });
} else {
dbm.saveRigaMagaz(codiceMagazzino, indexRiga, dataCreazione,
codiceLotto, qta);
}
}
displayList();
}
private void displayList() {
// TODO Auto-generated method stub
listaMagazzino = new LinkedList<LottiMagazzino>();
listView = (ListView) findViewById(R.id.list_view_mag);
Cursor cursor = dbm.queryInventarioMag("CODICE_MAGAZZINO=?",
new String[] { codiceMagazzino });
if (cursor != null) {
int i_codMag = cursor.getColumnIndex(DatabaseStrings.CAMPO_COD_MAG);
int i_riga = cursor.getColumnIndex(DatabaseStrings.CAMPO_RIGA);
int i_dataCr = cursor
.getColumnIndex(DatabaseStrings.CAMPO_DATA_CREAZIONE);
int i_codLotto = cursor
.getColumnIndex(DatabaseStrings.CAMPO_COD_LOTTO);
int i_qta = cursor.getColumnIndex(DatabaseStrings.CAMPO_QTA);
listaMagazzino.clear();
boolean hasNext = cursor.moveToFirst();
while (hasNext) {
listaMagazzino.add(new LottiMagazzino(cursor
.getString(i_codMag), cursor.getInt(i_riga), cursor
.getString(i_dataCr), cursor.getString(i_codLotto),
cursor.getDouble(i_qta)));
hasNext = cursor.moveToNext();
}
}
adapter = new AdapterMagazzino(this, R.layout.row_listview,
listaMagazzino);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
final Dialog dialog = new Dialog(InventarioMag.this);
dialog.setTitle("Dettaglio Riga DDT");
dialog.setContentView(R.layout.dialog_view);
listViewDialog = (ListView) dialog
.findViewById(R.id.listViewDialog);
LottiMagazzino lm = adapter.getItem(position);
listaInfo.clear();
listaInfo.add(new LabelValue("Codice Magazzino", lm
.getCodiceMagazzino()));
listaInfo.add(new LabelValue("Riga", lm.getRiga().toString()));
listaInfo.add(new LabelValue("Data Creazione", lm
.getDataCreazione()));
listaInfo.add(new LabelValue("Codice Lotto", lm
.getCodiceLotto()));
listaInfo.add(new LabelValue("Quantità", lm.getQuantita()
.toString()));
lbAdapter = new InfoAdapter(InventarioMag.this,
R.layout.row_info_lb, listaInfo);
listViewDialog.setAdapter(lbAdapter);
dialog.show();
}
});
}
Aucun commentaire:
Enregistrer un commentaire