Hello everyone,
I have a problem about onItemSelected method of Spinner. There is no problem if I only have one Spinner. I can set a listener on that. I have a DB stored in sqlite. There is a table in which a column field contains date with year-month-date format. Then I created two Spinner views. One for month, and other for year. My program wants to show the database queries based on selection from month and year.
The problem now, if I set listener only on month Spinner, it shows queries based on month. If I set listener on year Spinner, it shows queries based on year. Actually I already prepared sql queries matching both year and month queries. But it seems that the OnItemSelected listener only can accept "ONE" spinner instance at a time. I try to use monthview.getItemAtPosition(position) && yearview.getItemAtPosition(position) to match both requirements for month and year. But it failed.
I use public class xxx extends xxx implements OnItemSelected listener and add two methods.
spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int pos, long id) { // Do some stuff based onItemSelected } }
Does anyone know how to achieve this goal ?
In simple words, I have two spinners, one for month, one for year, values are populated via arrayadapter. Then I use SimpleCusrsorAdapter to get sql result from sqlite DB. Then I put cursor result into listadapter and associated with listview. It works without problem if I operate it individually either by month or year but not both. But it seems that listener only listen on one spinner instance not two or more at the same time. May be it is common problem. May be some of you already encountered this problem before.
Or can I use anonymous inner class ? But I think that it is different approach with same result. If not may be I need to use another technique if only one listener is available ?
I want to show, for example: -I select April and All years, it displays all entries in April (April in all years) -I select 2010 and All Months, it displays all entries in 2010 (Jan to Dec 2010) -I select April and 2010, it only displays all entries in April 2010
Thanks for explaination and suggestions !!
Tom Best Regards,