如何在特定阶段停止鼠标运动事件

时间:2016-04-21 04:14:14

标签: java android mousemotionevent

我是android新手。我在鼠标运动中有小问题,我不知道要处理。当在鼠标中向上或向下滚动以在达到特定值时更改按钮值时停止鼠标移动或不更改值。请建议我并提前感谢...

  

我的活动

public class MainActivity extends Activity {
Button  btn;
int x,f;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn=(Button)findViewById(R.id.btn);          
    btn.setOnGenericMotionListener(new OnGenericMotionListener() {
        @Override
        public boolean onGenericMotion(View v, MotionEvent event) {         
            switch (event.getAction()) {                        
            case MotionEvent.ACTION_SCROLL:
                if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) > 0.0f)
                {
                    x=Integer.parseInt(btn.getText().toString());
                    f=x+5;
                    btn.setText(""+f);
                    if(x==10)// this condition mouse scroll but not change btn value.
                    {
                        btn.settext("10");
                    }
                }
                else
                {
                    x=Integer.parseInt(btn.getText().toString());
                    f=x-5;
                    btn.setText(""+f);  
                }
            }
            return false;
        }           
    });
}}

1 个答案:

答案 0 :(得分:0)

please refer this link it help you to get the information

enter link description here