1

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

我的活动

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;
        }           
    });
}}
4

1 回答 1

0

请参考此链接它可以帮助您获取信息

在此处输入链接描述

于 2016-04-25T09:44:51.183 回答