Bonjour, Aidez moi please ! je suis entrain de suivre des tutos Android pour pouvoir créer et afficher, supprimer des données d'une base avec SQlite. j'ai pas mal de messages d'erreurs comme vous le voyez :voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 03-02 16:50:10.498 15864-15864/? E/Zygote: v2 03-02 16:50:10.498 15864-15864/? I/libpersona: KNOX_SDCARD checking this for 10268 03-02 16:50:10.498 15864-15864/? I/libpersona: KNOX_SDCARD not a persona 03-02 16:50:10.498 15864-15864/? I/SELinux: Function: selinux_compare_spd_ram, index[1], SPD-policy is existed. and_ver=SEPF_SM-A300FU_5.0.2-1 ver=51 03-02 16:50:10.498 15864-15864/? W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [2], priority version is VE=SEPF_SECMOBILE_6.0.1_0025 03-02 16:50:10.508 15864-15864/? W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=velo.velib 03-02 16:50:10.508 15864-15864/? I/art: Late-enabling -Xcheck:jni 03-02 16:50:10.568 15864-15864/? D/TimaKeyStoreProvider: TimaSignature is unavailable 03-02 16:50:10.568 15864-15864/? D/ActivityThread: Added TimaKeyStore provider 03-02 16:50:10.708 15864-15864/velo.velib W/System: ClassLoader referenced unknown path: /data/app/velo.velib-1/lib/arm 03-02 16:50:10.718 15864-15864/velo.velib I/InstantRun: Instant Run Runtime started. Android package is velo.velib, real application class is null. 03-02 16:50:10.788 15864-15864/velo.velib W/art: Failed to open zip archive '/system/framework/qcom.fmradio.jar': I/O Error 03-02 16:50:11.578 15864-15864/velo.velib W/System: ClassLoader referenced unknown path: /data/app/velo.velib-1/lib/arm 03-02 16:50:11.858 15864-15864/velo.velib D/SecWifiDisplayUtil: Metadata value : none 03-02 16:50:11.868 15864-15864/velo.velib D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{614c004 I.E...... R.....ID 0,0-0,0} 03-02 16:50:11.868 15864-16014/velo.velib D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 03-02 16:50:11.958 15864-16014/velo.velib I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8916_32_LA.BR.1.2.6_RB1__release_AU (Ia10634f51b) OpenGL ES Shader Compiler Version: XE031.06.00.05 Build Date: 01/04/16 Mon Local Branch: Remote Branch: quic/LA.BR.1.2.6_rb1.7 Local Patches: NONE Reconstruct Branch: NOTHING 03-02 16:50:11.968 15864-16014/velo.velib I/OpenGLRenderer: Initialized EGL, version 1.4 03-02 16:50:12.078 15864-15864/velo.velib D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 36 - 0, 0) vi=Rect(0, 36 - 0, 0) or=1 03-02 16:50:12.098 15864-16014/velo.velib D/libGLESv1: DTS_GLAPI : DTS is not allowed for Package : velo.velib 03-02 16:50:12.128 15864-15864/velo.velib I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@9cf1417 time:244492001 03-02 16:50:13.188 15864-15864/velo.velib D/ViewRootImpl: ViewPostImeInputStage processPointer 0 03-02 16:50:13.208 15864-15864/velo.velib D/ViewRootImpl: ViewPostImeInputStage processPointer 1 03-02 16:50:13.228 15864-15864/velo.velib I/Timeline: Timeline: Activity_launch_request id:velo.velib time:244493103 03-02 16:50:13.458 15864-15864/velo.velib D/SecWifiDisplayUtil: Metadata value : none 03-02 16:50:13.458 15864-15864/velo.velib D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{6537782 I.E...... R.....ID 0,0-0,0} 03-02 16:50:13.608 15864-15864/velo.velib D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 36 - 0, 0) vi=Rect(0, 36 - 0, 0) or=1 03-02 16:50:13.658 15864-15864/velo.velib I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@30c22cd time:244493532 03-02 16:50:13.698 15864-15864/velo.velib V/ActivityThread: updateVisibility : ActivityRecord{fd70bad token=android.os.BinderProxy@9cf1417 {velo.velib/velo.velib.Activities.MainActivity}} show : false 03-02 16:50:14.218 15864-15864/velo.velib D/ViewRootImpl: ViewPostImeInputStage processKey 0 03-02 16:50:14.318 15864-15864/velo.velib D/ViewRootImpl: ViewPostImeInputStage processKey 1 03-02 16:50:14.418 15864-15864/velo.velib I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@9cf1417 time:244494297 03-02 16:50:14.458 15864-15864/velo.velib D/ViewRootImpl: #3 mView = null 03-02 16:50:15.008 15864-15864/velo.velib D/ViewRootImpl: ViewPostImeInputStage processPointer 0 03-02 16:50:15.048 15864-15864/velo.velib D/ViewRootImpl: ViewPostImeInputStage processPointer 1 03-02 16:50:15.048 15864-15864/velo.velib I/Timeline: Timeline: Activity_launch_request id:velo.velib time:244494925 03-02 16:50:15.188 15864-15864/velo.velib D/AbsListView: Get MotionRecognitionManager 03-02 16:50:15.208 15864-15864/velo.velib E/MotionRecognitionManager: mSContextService = null 03-02 16:50:15.208 15864-15864/velo.velib E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@8da5e63 03-02 16:50:15.228 15864-15864/velo.velib E/SQLiteLog: (1) table "ETAT_STATION" has more than one primary key 03-02 16:50:15.238 15864-15864/velo.velib E/SQLiteLog: (1) table "ETAT_STATION" has more than one primary key 03-02 16:50:15.238 15864-15864/velo.velib D/AndroidRuntime: Shutting down VM 03-02 16:50:15.238 15864-15864/velo.velib E/AndroidRuntime: FATAL EXCEPTION: main Process: velo.velib, PID: 15864 java.lang.RuntimeException: Unable to start activity ComponentInfo{velo.velib/velo.velib.Activities.StationActivity}: android.database.sqlite.SQLiteException: table "ETAT_STATION" has more than one primary key (code 1): , while compiling: CREATE TABLE ETAT_STATION (DATEMTEXT PRIMARY KEY NOT NULL, NUMSTEXT PRIMARY KEY NOT NULL, ETATSTEXT ; ################################################################# Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (table "ETAT_STATION" has more than one primary key (code 1): , while compiling: CREATE TABLE ETAT_STATION (DATEMTEXT PRIMARY KEY NOT NULL, NUMSTEXT PRIMARY KEY NOT NULL, ETATSTEXT ;) ################################################################# at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) at android.app.ActivityThread.access$1100(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7331) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: android.database.sqlite.SQLiteException: table "ETAT_STATION" has more than one primary key (code 1): , while compiling: CREATE TABLE ETAT_STATION (DATEMTEXT PRIMARY KEY NOT NULL, NUMSTEXT PRIMARY KEY NOT NULL, ETATSTEXT ; ################################################################# Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (table "ETAT_STATION" has more than one primary key (code 1): , while compiling: CREATE TABLE ETAT_STATION (DATEMTEXT PRIMARY KEY NOT NULL, NUMSTEXT PRIMARY KEY NOT NULL, ETATSTEXT ;) ################################################################# at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1000) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:565) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59) at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1838) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1769) at velo.velib.Models.DatabaseOpenHelper.onCreate(DatabaseOpenHelper.java:42) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251) at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187) at velo.velib.Models.DAOBase.open(DAOBase.java:36) at velo.velib.Activities.StationActivity.onCreate(StationActivity.java:46) at android.app.Activity.performCreate(Activity.java:6904) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266) ... 9 more 03-02 16:50:17.408 15864-15864/velo.velib I/Process: Sending signal. PID: 15864 SIG: 9**class :BatabaseOpenHelper
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 **class :DAOBase package velo.velib.Models; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import java.sql.SQLException; import static velo.velib.Models.DatabaseOpenHelper.DATABASE_NAME; /** * Created by PC on 11/02/2017. */ public abstract class DAOBase { protected final static int VERSION = 1; //1 version de la base il faudra changer cet attribut si on a besoin de mettre a jour la base private static final String TAG = "Adapter"; private SQLiteDatabase bd; //pour des requetes private DatabaseOpenHelper database; //pour pouvoir instancier la class DatabaseOpenHelper public DAOBase(Context context) { database = new DatabaseOpenHelper(context,DATABASE_NAME,null,VERSION); } //les mthodes d'acces a l'ecriture et lire //---------------------------------------------- public SQLiteDatabase open() throws SQLException { // On ouvre la base de données en écriture try { bd = database.getWritableDatabase(); } catch (SQLiteException ex) { bd = database.getReadableDatabase(); } return bd; } //on ferme l'accès à la base de données public void close() { bd.close(); } //methode d'acces a la base de donnee pour faire certaines operations public SQLiteDatabase getDataBase() { return bd; } }
**class StationDAO
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 package velo.velib.Models; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; /** * Created by PC on 13/02/2017. */ public class DatabaseOpenHelper extends SQLiteOpenHelper { private static DatabaseOpenHelper sInstance; // VERSION de la bdd, permet les mises à jour des tables et champs au lancement de l'application private static final int VERSION = 1; // NOM de la base public static final String DATABASE_NAME = "BdVlib"; // TAG pour le log private static final String TAG = "Adapter"; public static synchronized DatabaseOpenHelper getInstance(Context context) { if (sInstance == null) { sInstance = new DatabaseOpenHelper(context.getApplicationContext(), DATABASE_NAME, DATABASE_NAME, VERSION); } return sInstance; } //constructeur pour accéder à la base de données n'importe où dans le code public DatabaseOpenHelper(Context context, String databaseName, String DATABASE_NAME, int version) { super(context,DATABASE_NAME, null, VERSION); } @Override //classe où on execute le script de creation de base public void onCreate(SQLiteDatabase db) { // Créer les tables db.execSQL(StationDAO.CREATE_TABLE); db.execSQL(Etat_StationDAO.CREATE_TABLE); db.execSQL(PlotsDAO.TABLE_CREATE); //db.execSQL(Etat_PlotDAO.CREATE_TABLE); // Insérer les données for (String insertS : StationDAO.getInsertSQL()) { db.execSQL(insertS); } for (String insertESt : Etat_StationDAO.getInsertSQL()) { db.execSQL(insertESt); } for (String insertPl : PlotsDAO.getInsertSQL()) { db.execSQL(insertPl); } } @Override //mettre à jour de la base de donnee public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // Log Log.w(TAG, "UPGRADING DATABASE FROM VERSION " +oldVersion + " TO " + newVersion + ", WHICH WILL DESTROY ALL OLD DATA !"); // DROP db.execSQL(StationDAO.DROP_TABLE); db.execSQL(Etat_StationDAO.DROP_TABLE); db.execSQL(PlotsDAO.DROP_TABLE); onCreate(db); } }
et **mon activity stationActivity.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 package velo.velib.Models; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import java.util.ArrayList; import java.util.List; import velo.velib.Metiers.Station; /** * Created by PC on 13/02/2017. */ public class StationDAO extends DAOBase{ // Nom de la table public static final String STATION_TABLE_NAME = "Station"; public static final String STATION_NUM = "numS"; public static final String STATION_ETATCS = "etatCs"; public static final String STATION_NOM = "nomS"; ////définir la façon dont la base de données sera ... public static final String STATION_SITUATION = "situationS"; public static final String STATION_CAPACITE = "capaciteS"; public static final String STATION_PRESENCEBORNE = "presenceborneS"; public static final String CREATE_TABLE = "CREATE TABLE " + STATION_TABLE_NAME + " (" + STATION_NUM + " integer primary key autoincrement, " + STATION_ETATCS + "TEXT not null," + //implementation STATION_NOM + " TEXT not null, " + STATION_SITUATION + " TEXT not null, " + STATION_CAPACITE + " INTEGER , " + STATION_PRESENCEBORNE + " TEXT);"; // retourne une chaîne de caractères représentant une instruction SQL de création de la table station public static final String DROP_TABLE = "DROP TABLE IF EXISTS " + STATION_TABLE_NAME + ";"; private static final String[] DATA = new String[]{ //données de la table "'1', 'FONCTIONNEL', 'TEST', 'TEST SITUATION', '5', 'OUI'", "'2', 'PANNE', 'TEST2', 'TEST2 SITUATION', '2', 'NON'"}; public StationDAO(Context context) { super(context); } // retourne une liste de chaînes de caractères représentant les instructions SQL d'insertion de données dans la table public static String[] getInsertSQL() { String insertSQL = "INSERT INTO " + STATION_TABLE_NAME + "(" + STATION_NUM + ", " + STATION_ETATCS + ", " + STATION_NOM + ", " + STATION_SITUATION + ", " + STATION_CAPACITE + ", " + STATION_PRESENCEBORNE + ") VALUES "; String[] liste = new String[DATA.length]; int i = 0; for (String station : DATA) { // Instruction SQL INSERT liste[i] = insertSQL + "(" + station + ")"; i++; } return liste; } public long insert(Station station) { // Création d'un ContentValues (fonctionne comme une HashMap) ContentValues values = new ContentValues(); // Ajout clé/valeur : colonne/valeur values.put(STATION_NUM, station.getNumS()); values.put(STATION_ETATCS, station.getEtatCS()); values.put(STATION_NOM, station.getNomS()); values.put(STATION_SITUATION, station.getSituation()); values.put(STATION_CAPACITE, station.getCapacite()); values.put(STATION_PRESENCEBORNE, station.getPresenceBorne()); // Insertion de l'objet dans la BD via le ContentValues return (getDataBase().insert(STATION_TABLE_NAME, null, values)); } public int update(Station station) { // Création d'un ContentValues (fonctionne comme une HashMap) ContentValues values = new ContentValues(); // Ajout clé/valeur : colonne/valeur values.put(STATION_NUM, station.getNumS()); values.put(STATION_ETATCS, station.getEtatCS()); values.put(STATION_NOM, station.getNomS()); values.put(STATION_SITUATION, station.getSituation()); values.put(STATION_CAPACITE, station.getCapacite()); values.put(STATION_PRESENCEBORNE, station.getPresenceBorne()); // Insertion de l'objet dans la BD via le ContentValues et l'identifiant return getDataBase().update(STATION_TABLE_NAME, values, STATION_NUM + " = " + station.getNumS(), null); } public int removeByNumStation(String numS) { //Suppression d'une station de la BD à partir du numero return getDataBase().delete(STATION_TABLE_NAME, STATION_NUM + " = " + numS, null); } public int remove(Station station) { return removeByNumStation(station.getNumS()); } public List<Station> selectAll() { //Récupère dans un Cursor les valeurs correspondant à des enregistrements de station contenu dans la BD Cursor cursor = getDataBase().rawQuery("SELECT * FROM " + STATION_TABLE_NAME, null); return cursorToListStation(cursor); } public List<Station> getStationParNumS(String numS) { Cursor cursor = getDataBase().rawQuery("SELECT * FROM " + STATION_TABLE_NAME + " WHERE " + STATION_NUM + "=?", new String[]{numS}); return cursorToListStation(cursor); } // méthode pour convertir un cursor en une liste de stations private List<Station> cursorToListStation(Cursor cursor) { // Récupére l'index des champs int indexNum = cursor.getColumnIndex(STATION_NUM); int indexEtat = cursor.getColumnIndex(STATION_ETATCS); int indexNom = cursor.getColumnIndex(STATION_NOM); int indexSituation = cursor.getColumnIndex(STATION_SITUATION); int indexCapacite = cursor.getColumnIndex(STATION_CAPACITE); int indexPresenceB = cursor.getColumnIndex(STATION_PRESENCEBORNE); // Declaration et initialisation d'une liste de question ArrayList<Station> liste = new ArrayList<>(); while (cursor.moveToNext()) { // Création d'une station Station station = new Station(); station.setNumS(cursor.getString(indexNum)); station.setEtatCS(cursor.getString(indexEtat)); station.setNomS(cursor.getString(indexNom)); station.setSituation(cursor.getString(indexSituation)); station.setCapacite(cursor.getInt(indexCapacite)); station.setPresenceBorne(cursor.getString(indexPresenceB)); // Ajout dans la liste liste.add(station); } // Fermeture du cursor cursor.close(); return liste; } // méthode qui permet de convertir un cursor en une station private Station cursorToFirstStation(Cursor cursor) { int indexNum = cursor.getColumnIndex(STATION_NUM); int indexEtat = cursor.getColumnIndex(STATION_ETATCS); int indexNom = cursor.getColumnIndex(STATION_NOM); int indexSituation = cursor.getColumnIndex(STATION_SITUATION); int indexCapacite = cursor.getColumnIndex(STATION_CAPACITE); int indexPresenceB = cursor.getColumnIndex(STATION_PRESENCEBORNE); // Declaration d'une question Station station = null; if (cursor.getCount() > 0) { //s'il y a quelque chose dans le cursor cursor.moveToFirst(); // Création d'une station station = new Station(); station.setNumS(cursor.getString(indexNum)); station.setEtatCS(cursor.getString(indexEtat)); station.setNomS(cursor.getString(indexNom)); station.setSituation(cursor.getString(indexSituation)); station.setCapacite(cursor.getInt(indexCapacite)); station.setPresenceBorne(cursor.getString(indexPresenceB)); } // Fermeture du cursor cursor.close(); // return station; } }
certaines erreurs que j'ai pu constaté c'est
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 package velo.velib.Activities; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.AdapterView; import android.widget.EditText; import android.widget.FilterQueryProvider; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.Toast; import java.sql.SQLException; import java.util.List; import velo.velib.Metiers.Station; import velo.velib.Models.StationDAO; import velo.velib.R; /** * Created by PC on 16/02/2017. */ public class StationActivity extends Activity { private ListView maListViewStation; private StationDAO elt; private StationDAO elementHelper; private SimpleCursorAdapter dataAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.station_display); elementHelper = new StationDAO(this); try { elementHelper.open(); } catch (SQLException e) { e.printStackTrace(); AffichageListView(); } } //Récupération de la listview créée dans le fichier main.xml //Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem /* SimpleAdapter display = new SimpleAdapter(this, null, R.layout.affichagestation, new String[] {StationDAO.STATION_NOM, StationDAO.STATION_ETATCS}, new int[]{R.id.nomS, R.id.etatS}); //On attribut à notre listView l'adapter que l'on vient de créer maListViewStation.setAdapter(display); */ private void AffichageListView() { List<Station> cursor = elementHelper.selectAll(); // The desired columns to be bound String[] columns = new String[] { StationDAO.STATION_NUM, StationDAO.STATION_NOM, StationDAO.STATION_ETATCS, }; // Les vues XML définies auxquelles les données seront liées int[] to = new int[] { R.id.nomS, R.id.etatS, }; //Créez l'adaptateur en utilisant le curseur pointant vers les données désirées //Ainsi que les informations de mise en page dataAdapter = new SimpleCursorAdapter( this, R.layout.affichagestation, (Cursor) cursor, columns, to, 0); ListView listView = (ListView) findViewById(R.id.listviewStation); // Assign adapter to ListView listView.setAdapter(dataAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView listView, View view, int position, long id) { // Placez le curseur sur la ligne correspondante pour le résultats Cursor cursor = (Cursor) listView.getItemAtPosition(position); // Get the state's capital from this row in the database. String countryCode = cursor.getString(cursor.getColumnIndexOrThrow("code")); Toast.makeText(getApplicationContext(), countryCode, Toast.LENGTH_SHORT).show(); } }); EditText myFilter = (EditText) findViewById(R.id.myFilter); myFilter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { dataAdapter.getFilter().filter(s.toString()); } }); dataAdapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return (Cursor) elementHelper.getStationParNumS(constraint.toString()); } }); } }etc
Code : Sélectionner tout - Visualiser dans une fenêtre à part SQL(query) error or missing database
pouvez vous me dire où est que j'ai fait une erreurs svp ?
Merci d'avance !
Partager