I am developing an android application which in I have a class A
. The A
class have a spinner, and there is a B class which have the spinner's onItemSelected()
, B implements OnItemSelectedListener
and B
is public.
I want to call a function in A
when a newer item has selected. So if there selected the first
item, and I change it to the second
then I want call a function from class A
.
I always want to call the same A
's function. It's refreshes a list.
How can I do that?
There's the class A
's spinner which call in A
's onCreate
:
public void addListenerOnSpinnerItemSelection() {
pspinner = (Spinner) findViewById(R.id.spinner1);
pspinner.setOnItemSelectedListener(new B());
}
And the B class:
public class B implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id){
Toast.makeText(parent.getContext(),
"The selected place: " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
A.refresh(); //I think I should call A's function like that but
// Android Studio tells meg that refresh() must be static
}
}
Should I call the A
's function in addListenerOnSpinnerItemSelection()
? Or in B
's onItemSelected
? But how?
Unfortunatelly it's not work that way above. How can I call A's function without make refresh()
static?
The spinner gets its elements from an xml.