use*_*974 6 java android android-spinner
我有一个微调器,我想检测用户何时点击它.当用户单击它打开时,我想调用端点,然后用新数据更新微调器.但我无法弄清楚如何做到这一点并导致无限循环:
我在这里调用API:
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// Call API here
// Do render with old data.
}
Run Code Online (Sandbox Code Playgroud)
当API成功时,我调用更新:
@Override
public void onSuccess(final Response response) {
Helper.update(...);
}
public void update(...) {
...
adapter.setItems(newData);
adapter.notifyDataSetChanged();
}
Run Code Online (Sandbox Code Playgroud)
然后getDropDownView()再次触发.在用户点击打开微调器后,我无法弄清楚还有什么叫getDropDownView().我怎么解决这个问题?
Rak*_*esh 11
您可以在Spinner上设置Touch-listener来检测点击.
findViewById(R.id.spinner).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(MainActivity.this,"CallAPI",Toast.LENGTH_SHORT).show();
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
并从onTouch返回False以正常运行.我希望它对你有用.
| 归档时间: |
|
| 查看次数: |
3571 次 |
| 最近记录: |