Does Android Have This Function "how To Filter Based On Spinner?"?
I would like to ask a very general question. ' How to filter based on spinner?' Meaning, there's few option in spinner ('education', 'musuem', 'restaurant') Upon selecting 'museum'
Solution 1:
first of all you should implement OnItemSelectedListener
.
Spinner sp;
String[] strarr={"education", "musuem", "restaurant"};
ArrayAdapter<String> adapter = newArrayAdapter<String>(filename.this,android.R.layout.simple_spinner_item,strarr);
sp=(Spinner) findViewById(R.id.spinner1);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(this);
you should override
publicvoidonItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3){
int position =sp.getSelectedItemPosition();
//things to do
}
andpublicvoidonNothingSelected(AdapterView<?> arg0){
//things to do
}
Solution 2:
Yes there is a Listener named OnItemSelectedListener which tells you which item selected in the spinner so you can find the selected item id, then filter your adapter or whatever data structure you have with that selected Item.
Spinner.setOnItemSelectedListener(newOnItemSelectedListener() {
@OverridepublicvoidonItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
})
});
Post a Comment for "Does Android Have This Function "how To Filter Based On Spinner?"?"