In my android application I have flowers that have a column called location which stores the city they are found. In my list view while returning the different cities I am receiving a separate row for each flower that contains a city location. Instead I would like to check if there are duplicates so that I only have one row that shows "Los Angeles" instead of 4. I then want to be able to derive the number of times that a particular city appears as a value in the column so I can display the number of times that it (In this case the number of flowers in this city) occurs in a textview.
I'm using a cursor to grab the data that I am using however not sure how to make such commands within the Android, SQlite interface of this.
Below is my cursor definition
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
switch (id) {
case LOADER_ID:
return new CursorLoader(
getContext(),
DatabaseDescription.Flower.CONTENT_URI,
FROM_COLUMNS,
COLUMN_LOCATION + "<> ''",
null,
COLUMN_LOCATION + " ASC"
);
default:
if (BuildConfig.DEBUG)
throw new IllegalArgumentException("no id handled!");
return null;
}
}
I doubt you need to see my adapter as the Cursor is responsible for the content that I receive. Most important is to know how to not display duplicates and how to count number of rows that have the same value in the particular column. Appreciate the assistance.