I am currently doing a project that involves showing a list of locations nearby based on my current location.
I just started Android Programming not long ago, so I am still at my learning while coding phase.
I searched all over trying to get some clues on how to proceed. I am still stuck after reading and trying out.
My working code currently consists of
Questions
What is the "correct" way to filter entries for my ListView? I saw posts on Filter/Filterable interface, but it doesn't seems to work for my current setup? Do I perform filtering inside my Custom CursorAdapter?
How should I refresh my ListView after I perform filtering? Do I call getLoaderManager().restartLoader(0, null, this) or adapter.notifyDataSetChanged() ?
Thanks in advance.
Use getLoaderManager().restartLoader(LOADER_ID, null, MainActivity.this);
to recall onCreateLoader
.
Android developer site example.
private String filter;
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_filter :
filter = "COLUMN_NAME = value";
getLoaderManager().restartLoader(LOADER_ID, null, MainActivity.this);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public android.content.Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(
MainActivity.this, // Parent activity context
SomeContentProvider.CONTENT_URI, // Table to query
projection, // Projection to return
filter, // No selection clause
null, // No selection arguments
null // Default sort order
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With