gpt4 book ai didi

android - longClick 监听器的持续时间

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:30 25 4
gpt4 key购买 nike

我想缩短 ListView 响应长点击监听器的时间。是否可以减少长点击持续时间?

getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
final int position, long id) {

if(selectedHabit){
Intent intent = new Intent(parent.getContext(),AddScheduleEventActivity.class );
startActivityForResult(intent, CREATE_EVENT);
return true;
}



return false;
}
});

最佳答案

您可以使用 OnTouchListener:

    private int lastTouchedViewId = -1;
private long duration = System.currentTimeMillis();
private long LONG_CLICK_DURATION = 1000;

...

view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {


switch (motionEvent.getAction()) {


case MotionEvent.ACTION_DOWN:
if (lastTouchedViewId != view.getId()) {
lastTouchedViewId = view.getId();
duration = System.currentTimeMillis();
}
else
{

if(duration-System.currentTimeMillis()> LONG_CLICK_DURATION)

doStuff();
}
return true;

case MotionEvent.ACTION_UP:
lastTouchedViewId = -1;
return true;
}


return false;
}
});

关于android - longClick 监听器的持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27834675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com