I have a spinner and I want to detect when the user clicked on it. When the user clicks it open, I want to call an endpoint and then update the spinner with new data. But I couldn't figure out how to do this and results in infinite loop:
I call the API in here:
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// Call API here
// Do render with old data.
}
when the API successes, I call the to update:
@Override
public void onSuccess(final Response response) {
Helper.update(...);
}
public void update(...) {
...
adapter.setItems(newData);
adapter.notifyDataSetChanged();
}
and then this triggers getDropDownView()
again. I couldn't figure out what else is called after the user clicks open the spinner besides getDropDownView()
. How can I solve this problem?