Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid set new Cursor to a listView
    primarykey
    data
    text
    <p>I have a little issue with settings a new <code>Adapter</code> to a <code>listView</code> when user enter letters in <code>EditText</code>. So the thing which I'm doing is, when my <code>Activity</code> starts for the first time, I'm populating the listView from Database with Cursor and Custom Adapter. When user enter some text in EditText I'm creating new sql statement and getting the data with new Cursor. After that I'm creating new Custom Adapter and trying to set it to my list view.</p> <p>The problem is that when I start typing in edit text I can saw in Logs from LogCat that the sql statement is the right one, and cursor size, but my ListView isn't populated with the new data. It's staying the same. Here is how I'm doing it :</p> <p>This is how I'm populating the listView for first time :</p> <pre><code>cursor = userDbHelper.executeSQLQuery(sqlQuery); if (cursor.getCount() == 0) { noCards.setVisibility(View.VISIBLE); noCards.setText(getString(R.string.no_cards)); } else if (cursor.getCount() &gt; 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() &gt; 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); </code></pre> <p>and this is how I'm creating the new Cursor and adapter with <code>TextWatcher</code> :</p> <pre><code>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() &gt; 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() &gt; 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); } }); </code></pre> <p>So any ideas how can I refresh my list View with the new adapter. I've already tried with <code>adapter.notifySetDataChanged();</code> and it's not working.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload