J'ai un petit problème avec les paramètres un nouveau Adapter
à un listView
lorsque l'utilisateur entrer des lettres EditText
. Donc, la chose que je fais est, quand mon Activity
démarre pour la première fois, je remplis le listView de base de données avec Cursor et adaptateur personnalisé. Lorsque l'utilisateur saisit du texte dans EditText, je crée une nouvelle instruction sql et j'obtiens les données avec le nouveau Cursor. Après cela, je crée un nouvel adaptateur personnalisé et j'essaie de le définir dans ma liste. Le problème est que lorsque je commence à taper du texte d'édition, je peux voir dans Logs de LogCat que l'instruction sql est la bonne, et la taille du curseur, mais mon ListView n'est pas rempli avec les nouvelles données. Ça reste le même. Voici comment je le fais:Android set nouveau Curseur à une listeVoir
Voilà comment je suis peuplant la listView pour la première fois:
cursor = userDbHelper.executeSQLQuery(sqlQuery);
if (cursor.getCount() == 0) {
noCards.setVisibility(View.VISIBLE);
noCards.setText(getString(R.string.no_cards));
} else if (cursor.getCount() > 0) {
noCards.setVisibility(View.GONE);
for (cursor.move(0); cursor.moveToNext(); cursor.isAfterLast()) {
objectId = Integer.parseInt(cursor.getString(cursor.getColumnIndex("objectId")));
cardId.add(objectId);
title = cursor.getString(cursor.getColumnIndex("title"));
catTitle = cursor.getString(cursor.getColumnIndex("catTitle"));
int repeats = Integer.parseInt(cursor.getString(cursor.getColumnIndex("repeatsCount")));
count.add(repeats);
if(extra != 0){
String cardsm = "SELECT objectId FROM cardmedias "
+ "WHERE cardId="
+ objectId
+ " AND mediaType="
+ 5012;
Cursor cardsM = userDbHelper.executeSQLQuery(cardsm);
if (cardsM.getCount() == 0) {
} else if (cardsM.getCount() > 0) {
for (cardsM.move(0); cardsM.moveToNext(); cardsM.isAfterLast()) {
objectID = Integer.parseInt(cardsM.getString(cardsM.getColumnIndex("objectId")));
String filename = "mediacard-"+objectID;
if(storageID==1){
path = RPCCommunicator.getImagePathFromInternalStorage(servername, userId, filename, this);
} else if(storageID==2){
path = RPCCommunicator.getImagePathFromExternalStorage(servername, userId, filename);
}
hm.put(objectID, path);
path = hm.get(objectID);
Log.i("","path : "+path);
paths.add(path);
names.add(title);
categories.add(catTitle);
}
}
} else if (extra==0){
names.add(title);
categories.add(catTitle);
}
}
}
cursor.close();
adapter = new LazyAdapter(this, paths, names, categories, count);
listView.setAdapter(adapter);
et voici comment je crée le nouveau curseur et l'adaptateur avec TextWatcher
:
searchString = "";
sqlQuery = getSqlQuery(sort, collId, ascDesc,searchString);
searchBar.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void afterTextChanged(Editable s) {
check = 1;
listView.setAdapter(null);
searchString = s.toString();
Log.e("","searchString : "+searchString);
sqlQuery = getSqlQuery(sort, collId, ascDesc,searchString);
Log.e(""," sqlquery : "+sqlQuery);
Cursor cursor = userDbHelper.executeSQLQuery(sqlQuery);
Log.e("","cursor count : "+cursor.getCount());
if (cursor.getCount() == 0) {
noCards.setVisibility(View.VISIBLE);
noCards.setText(getString(R.string.no_cards));
} else if (cursor.getCount() > 0) {
noCards.setVisibility(View.GONE);
for (cursor.move(0); cursor.moveToNext(); cursor.isAfterLast()) {
objectId = Integer.parseInt(cursor.getString(cursor.getColumnIndex("objectId")));
cardId.add(objectId);
title = cursor.getString(cursor.getColumnIndex("title"));
catTitle = cursor.getString(cursor.getColumnIndex("catTitle"));
int repeats = Integer.parseInt(cursor.getString(cursor.getColumnIndex("repeatsCount")));
count.add(repeats);
if(extra != 0){
String cardsm = "SELECT objectId FROM cardmedias "
+ "WHERE cardId="
+ objectId
+ " AND mediaType="
+ 5012;
Cursor cardsM = userDbHelper.executeSQLQuery(cardsm);
if (cardsM.getCount() == 0) {
} else if (cardsM.getCount() > 0) {
for (cardsM.move(0); cardsM.moveToNext(); cardsM.isAfterLast()) {
objectID = Integer.parseInt(cardsM.getString(cardsM.getColumnIndex("objectId")));
String filename = "mediacard-"+objectID;
if(storageID==1){
path = RPCCommunicator.getImagePathFromInternalStorage(servername, userId, filename, OwnedStampii.this);
} else if(storageID==2){
path = RPCCommunicator.getImagePathFromExternalStorage(servername, userId, filename);
}
hm.put(objectID, path);
path = hm.get(objectID);
Log.i("","path : "+path);
paths.add(path);
names.add(title);
categories.add(catTitle);
}
}
} else if (extra==0){
names.add(title);
categories.add(catTitle);
}
}
}
cursor.close();
LazyAdapter adapter = new LazyAdapter(OwnedStampii.this, paths, names, categories, count);
listView.setAdapter(adapter);
}
});
Donc, des idées comment puis-je actualiser ma liste avec la nouvelle carte. J'ai déjà essayé avec adapter.notifySetDataChanged();
et ça ne marche pas.
Merci d'avance!