我有一个列表视图,如果长按向上或向下,我需要连续滚动 如果短按上下键,我想要单列表导航。我尝试使用按键长按监听器,但每次单击向上或向下按钮时,它都会进入上键监听器或按键监听器
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch(keyCode)
{
case 23:
Log.v("onkeylong_pressed","onkey_longpressed="+keyCode);
return true;
case 21:
Log.v("onkeylong_pressed","onkey_longpressed="+keyCode);
return true;
case KeyEvent.KEYCODE_DPAD_DOWN:
Log.v("onkeylong_pressed","onkey_longpressed="+keyCode);
return true;
}
//return true;
return super.onKeyLongPress(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
scroll.setSmoothScrollingEnabled(false);
WheelView wheelView = getWheel(R.id.category_wheel);
int currentItemIndex = wheelView.getCurrentItem();
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_DOWN:
wheelView.setCurrentItem(currentItemIndex + 1);
return true;
case KeyEvent.KEYCODE_DPAD_UP:
if (currentItemIndex == 0) {
currentItemIndex = itemsList.size() - 1;
}
scroll.setScrollX(0);
wheelView.setCurrentItem(currentItemIndex - 1);
Index_Right=0;x=150;
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
return true;
case KeyEvent.KEYCODE_DPAD_LEFT:
return true;
}
return super.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch(keyCode){
case KeyEvent.KEYCODE_DPAD_DOWN:
long_Press=true;
event.startTracking();
return true;
}
return super.onKeyDown(keyCode, event);
}
任何人都可以帮帮我。谢谢。