I got a big problem. I made a list view. But I wanna make the list view act on some operation like long press and touch up as well as some basic list view operation like scroll up and down. I try to use setOnItemLongClickListener
on the list view for long press and setOnTouchListener
for touch up action. But, they doesn't work well, especially for setOnTouchListener
with ACTION_UP
. When I press the screen for long time and then touch up, the OnItemLongClickListener
is called but onTouchListener
is not called at all. Besides, when there's few items in the list view, OnItemLongClickListener
would not be triggered if pressing at bottom of the list view.
So, I tried another way. I made a button with the same size of the list view and make button to act on long press and finger up. I made the button with no background and put it overlapped with the list view. But, another problem comes. If the button is in the up side, the list view can not scroll up and down. On the other hand, if list view is up, button can't act on long press and touch up.
By the way, I return false in both OnItemLongClickListener
and onTouchListener
. Why Android don't dispatch the screen actions to both views at the same place?
Instead of using two views, i would stick with only the listview, but using the good listeners, you can do what you want. Assuming you want an actionUp() method, you can call it at the end of the classic listview callbacks, in your case, that might be:
lv.setOnItemLongClickListener(new OnItemLongClickListener() { ...call actionUp() at the end
As well as in the end of the classic
lv.setOnItemClickListener(new OnItemClickListener() { ...call actionUp() at the end
As well as at the end of
lv.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == SCROLL_STATE_IDLE) {
//if we went from SCROLL_STATE_TOUCH_SCROLL to SCROLL_STATE_IDLE then a touch up occured somehow
actionUp();
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.