相关疑难解决方法(0)

Android - 按住按钮重复操作

大家早,

我会直接承认,我是开发新手并尝试使用Android.我一直在尝试搜索'网络以找到关于如何实现一些"按钮重复操作"的建议 - 我已经从按钮创建了一个自定义小键盘,并希望有类似退格的行为.到目前为止,我曾经拜访过一位没有编过Android的朋友,但他做了很多C#/ Java,似乎知道他在做什么.

下面的代码工作正常,但我觉得它可以更整齐地完成.如果我错过了比特,我很抱歉,但希望这能解释我的做法.我认为onTouchListener没问题,但处理Threads的方式并不合适.

有没有更好或更简单的方法来做到这一点?

谢谢,

中号

public class MyApp extends Activity {

private boolean deleteThreadRunning = false;
private boolean cancelDeleteThread = false;
private Handler handler = new Handler();

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    //May have missed some declarations here...

    Button_Del.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

           switch (event.getAction())
           {
               case MotionEvent.ACTION_DOWN:
               {
                   handleDeleteDown();
                   return true;
               }

               case MotionEvent.ACTION_UP:
               {
                   handleDeleteUp();
                   return true;
               }

               default:
                   return false;
           }
        }

        private void handleDeleteDown() {

            if …
Run Code Online (Sandbox Code Playgroud)

android handler ontouchlistener

53
推荐指数
5
解决办法
4万
查看次数

什么时候会触发ACTION_OUTSIDE?

我不明白何时触发ACTION_OUTSIDE.请举个例子.

文档给出了这个神秘的描述:

getAction()的常量:移动发生在UI元素的正常边界之外.这不提供完整的手势,而只提供移动/触摸的初始位置.

http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_OUTSIDE

android

10
推荐指数
1
解决办法
5312
查看次数

onTouch期间不会触发MotionEvent.ACTION_CANCEL

我有这个问题ACTION_CANCEL没有被触发,我已经在我的其他项目中实现了它并且工作正常.似乎ACTION_UP是唯一MotionEvent被称之为的ACTION_DOWN.ACTION_CANCEL一旦我的手指不再在视野中或屏幕外,我想触发.

示例场景:我点击视图,这是一个LinearLayout btw,在ACTION_DOWN其背景上更改为图像的"单击/暗淡"版本,并且当ACTION_UP触发时,只有当手指在LinearLayout内时,其背景才会变回默认图像.现在的问题是,当我按下它并将手指放在屏幕上,并将我的手指拖到LinearLayout之外时,ACTION_UP仍然会触发它应该没有的位置.

这是我的代码:

    dimView.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(final View view,
                final MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                Log.d("TAG", "DOWN");
                return true;
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                Log.d("TAG", "UP");
                return true;
            } else if (motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                Log.d("TAG", "CANCEL");
                return true;
            }
            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

其中:dimView是一个LinearLayout

android ontouchlistener motionevent

6
推荐指数
2
解决办法
3793
查看次数

标签 统计

android ×3

ontouchlistener ×2

handler ×1

motionevent ×1