"QuoteTable" is a java class file that defines a database. The code below works perfectly fine.
// mCategory = (Spinner) findViewById(R.id.category); - created during OnCreate method
private void fillData() {
// Fields from the database (projection)
// Must include the _id column for the adapter to work
String category = (String) mCategory.getSelectedItem();
String[] from = new String[] { QuoteTable.COLUMN_QUOTE };
// Fields on the UI to which we map
int[] to = new int[] { R.id.label };
getLoaderManager().initLoader(0, null, this);
adapter = new SimpleCursorAdapter(this, R.layout.motivate_row, null, from,
to, 0);
setListAdapter(adapter); }
What I want to do is, select particular quotes from "QuoteTable" depending on the category selected in the Spinner. This category should match the COLUMN_CATEGORY field in "QuoteTable." So I tried this -
private void fillData() {
String[] from = null;
// Fields from the database (projection)
// Must include the _id column for the adapter to work
if(category.equals("All")){
from = new String[] { QuoteTable.COLUMN_QUOTE };
}
else{
if(category.equals(QuoteTable.COLUMN_CATEGORY))
from = new String[] { QuoteTable.COLUMN_QUOTE };
}
// Fields on the UI to which we map
int[] to = new int[] { R.id.label };
getLoaderManager().initLoader(0, null, this);
adapter = new SimpleCursorAdapter(this, R.layout.motivate_row, null, from,
to, 0);
setListAdapter(adapter); }
/* this error is resolved */ This gives me a "SimpleCursorAdapter" error at if(category == "All")
Why is this the case? I've already used Cursor in another class to run a query in saving the database. This is merely my "View" and I want don't want to re-use that code.
Okay, now the previous (above mentioned) error is resolved. I had to fix the spinner in the layout file. However, although now there are no errors (runtime or compile time), the code logically does not do what I intend it to do. The spinner is present, but on selecting different options, nothing changes.