在我的鬧鐘應用程序中: 主要活動包含具有文本視圖和切換按鈕的列表視圖,我已應用到選中的更改監聽器上。每當我打開或關閉一個鬧鐘時,它會顯示一條消息「鬧鐘已打開」或「鬧鐘已關閉」。但是,當我向下滾動,然後向上滾動同樣的消息再次出現。如果我繼續向下滾動,然後再一次顯示消息。看起來,在滾動時一次又一次執行選中的更改偵聽器中的代碼。請告訴我如何解決這個問題。我不想在滾動時一次又一次地在選中的更改監聽器中執行代碼。listview with switch and on checked change listener issue
0
A
回答
0
請勿使用checked change listener
。嘗試讓交換機的onclicklistener
,並把支票這樣
yourswitch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
yourswitch.setChecked(!yourswitch.getChecked());
// update your data model if needed.
}
});
你都面臨這個問題,因爲當您滾動列表時perticular視圖進入存儲它嘗試檢查或在你的數據模型的基礎上取消交換機結果checkedChange listener
一次又一次地被調用。
對於SwitchDrag案例。
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
yourswitch.setChecked(!yourswitch.getChecked());
// update your data model if needed.
break;
case MotionEvent.ACTION_DOWN:
break;
}
return true;
}
});
嘗試實施onTouchLisrtener
。當用戶拖動開關並拿起他的手指時,我相信case MotionEvent.ACTION_UP
會被調用。
相關問題
- 1. BlackBerry BitmapField on focus change and click listener
- 2. jquery trigger('click')and on(change)
- 3. Extjs 4.1 Check Change Listener
- 4. listview with imageview and visibility
- 5. spring:batch listener issue
- 6. Switch Statement constant issue
- 7. java Field change listener
- 8. Babelify「use strict」issue with gulp and jsx
- 9. Listview Sort with Drag and Drop Android
- 10. Heroku with ruby on rails and Mongoid
- 11. Django Switch language with i18n pattern and normal url_pattern
- 12. Python Property Change Listener Pattern
- 13. Value Change Listener to JTextField
- 14. jquery background-color change on focus and blur
- 15. listview checked
- 16. EditText on click listener
- 17. Ajax and IE8 Issue
- 18. onclick and change innerhtml
- 19. jquery switch case background change
- 20. Switch 2 views with switch controller
- 21. Laravel with OAuth2 issue
- 22. Angular JS with jQuery Issue
- 23. git review not working-change id issue
- 24. on OptionsMenu click listener
- 25. HTML:Font Weight and Style Issue
- 26. Swift NSTimer and shouldPerformSegueWndIdentifier issue
- 27. SQL分揀WITH GROUP ISSUE BY
- 28. checked listview items
- 29. Switch Statement and Case
- 30. Switch Statement and Strings
發佈您的適配器的getView方法。 – Kartheek
雖然你想改變它,當你的開關狀態改變? –