Answer the question
In order to leave comments, you need to log in
Why are insets overwritten?
Hello, I ran into a problem. Google did not help, when writing a certain collection in SQLite, the records in the database are overwritten. When calling getItemCount() it shows 1 item.
PS I shove 3 elements I
write a collection of objects:
public void pushData(SQLiteDatabase db){
List<User> users = Main.createList(); // Тестовая коллекция
for (int i = 0; i < users.size(); i++) {
ContentValues value = new ContentValues();
value.put(KEY_NAME, users.get(i).getName());
value.put(KEY_GENDER, users.get(i).getGender());
value.put(KEY_CITY, users.get(i).getCity());
value.put(KEY_LATITUDE, users.get(i).getLocation().latitude);
value.put(KEY_LONGITUDE, users.get(i).getLocation().longitude);
db.insert(TABLE_NAME, null, value);
}
}
public int getItemCount(){
db = dbHelper.getReadableDatabase();
cursor = db.query(DBHelper.TABLE_NAME,null,null,null,null,null,null);
int cnt = cursor.getCount();
cursor.close();
close();
return cnt;
}
Toast.makeText(getApplication(),"Количество записе в базе: " + db.getItemCount(), Toast.LENGTH_LONG).show();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question