mardi 29 septembre 2015

Android listview with sqlite can't display rows with same values in database

i have problem When I'm adding new row to SQLite db with same values like: COLUMN_POSILKI_HISTORIA: Sugar COLUMN_WAGA_HISTORIA: 170 COLUMN_POSIKI_HISTORIA_DATA: 2015-09-29

and want to add again COLUMN_POSILKI_HISTORIA: Sugar COLUMN_WAGA_HISTORIA: 170 COLUMN_POSIKI_HISTORIA_DATA: 2015-09-29

i cant?? tell me why?? or maybe its adding to db but i cant show it in ListView???

I Can add: COLUMN_POSILKI_HISTORIA: Sugar COLUMN_WAGA_HISTORIA: 180 <---- change only this COLUMN_POSIKI_HISTORIA_DATA: 2015-09-29

How i create all of this:

private static final String STWORZ_TABELE_HISTORIA =
        "CREATE TABLE " + TABLE_HISTORIA_POSILKOW + " (" +
                COLUMN_ID_HISTORIA + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                COLUMN_POSILKI_HISTORIA + " TEXT NOT NULL , " +
                COLUMN_WAGA_HISTORIA + " REAL NOT NULL, " +
                COLUMN_POSILKI_HISTORIA_DATA + " DATA NOT NULL" +
                ");";

My Code in DBHandler:

public void addZjedzonyPosilek (String nazwaPosilekZjedzony, Integer wagaPosilekZjedzony, String dataDzis){


    SQLiteDatabase db = getWritableDatabase();

    db.execSQL("INSERT INTO " + TABLE_HISTORIA_POSILKOW + " (" + COLUMN_POSILKI_HISTORIA + ", " + COLUMN_WAGA_HISTORIA + ", " + COLUMN_POSILKI_HISTORIA_DATA + ") " +
            "VALUES ('" + nazwaPosilekZjedzony+"', " +wagaPosilekZjedzony+ ", "+dataDzis +");");

    db.close();
}

This is from Activity where i use ListView on ClickItemListener

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursorZjedzone = myDB.getWszystkiePosilki();
            obslugaData.getFormattedDate();
            String dataDZIS = formattedDate;
            String nazwaPosilkuHistoria;
            Integer wagaPosilkuHistoria;

            long z = adapterH.getItemId(position);
            int i = (int) z;
            cursorZjedzone.moveToPosition(i);

            nazwaPosilkuHistoria=cursorZjedzone.getString(cursorZjedzone.getColumnIndex(DBHandler.COLUMN_POSILKI));
            wagaPosilkuHistoria=cursorZjedzone.getInt(cursorZjedzone.getColumnIndex(DBHandler.COLUMN_WAGA));
            Toast.makeText(Activity_wybierzPosilek.this, nazwaPosilkuHistoria + " " + dataDZIS, Toast.LENGTH_SHORT).show();
            Toast.makeText(Activity_wybierzPosilek.this, wagaPosilkuHistoria + " " + formattedDate, Toast.LENGTH_SHORT).show();
            myDB.addZjedzonyPosilek(nazwaPosilkuHistoria, wagaPosilkuHistoria, dataDZIS);


        }
    });

My ListView:

private void allposilkiListView(){
    Cursor cursorPosilkiH = myDB.getWszystkiePosilkiHistoria();
    String nazwaPosilku;
    int wagaPosilku;
    nazwaPosilkuListHistoria.clear();
    wagaPosilkuListHistoria.clear();

    if (cursorPosilkiH.moveToFirst()){
        do {
            nazwaPosilku=cursorPosilkiH.getString(cursorPosilkiH.getColumnIndex(DBHandler.COLUMN_POSILKI));
            wagaPosilku=cursorPosilkiH.getInt(cursorPosilkiH.getColumnIndex(DBHandler.COLUMN_WAGA));
            nazwaPosilkuListHistoria.add(nazwaPosilku);
            wagaPosilkuListHistoria.add(wagaPosilku);
        }
        while (cursorPosilkiH.moveToNext());
    }
    cursorPosilkiH.close();
}

private void singlePosilek(){

}

Aucun commentaire:

Enregistrer un commentaire