error loadind data from sqlite to spinner

51 views Asked by At

While loading data from SQLite to spinner the data are repeated several times, values "Traditionnel" and "fast food" are repeated several times

    @Override
    protected void onCreate(Bundle savedInstanceState) {


               ContentValues values = new ContentValues();
               values.put(COLUMN_CATEGORIENAME , "fast food");
               db.insert(TABLE_CATEGORIE, null, values);
               values.put(COLUMN_CATEGORIENAME , "Traditionnel");
               db.insert(TABLE_CATEGORIE, null, values);

               db.insert(TABLE_CATEGORIE, null, values);
               Cursor c = db.query(TABLE_CATEGORIE,  new String[] { COLUMN_IDCATEGORIE, COLUMN_CATEGORIENAME}   , null,null,null,null,null);


            int col=c.getCount();   


                    if (col == 0) {
                        Toast.makeText(MainActivity.this, "Pas de donnees ", Toast.LENGTH_LONG).show();
                        // effacer le contenue champ login et mot de passe

                        }
                    else {
                        // col =1  il ya un utilisateur qui verifie la condition
                        c.moveToFirst();
                           while (c.isAfterLast() == false) {
                               // conversion int to string casting 
                               String ch1=""+c.getInt(0);
                                String ch2=c.getString(1);
                               adapter.add(ch2);
                                c.moveToNext();
                            }
                    }   
                    c.close();  


                     Spinner s = (Spinner) findViewById(R.id.spinner1);
                    s.setAdapter(adapter);  
0

There are 0 answers