【发布时间】:2016-04-28 08:42:42
【问题描述】:
先生, 我正在使用按钮键,如果我将鼠标光标指向按钮,它会显示一些值,例如 Eg:5,然后在使用鼠标滚动的 setOnGenericMotionListener 事件上,Eg:5 会根据鼠标滚动而变化以增加和减少值但是现在我想移动鼠标光标点的任何位置需要使用鼠标滚动事件设置 setOnGenericMotionListener 事件来处理该特定按钮如何执行此事件?
活动
public class MainActivity extends Activity {
Button button;
int x,f;
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button1);
button.setOnGenericMotionListener(new OnGenericMotionListener() {
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) > 0.0f)
{
x=Integer.parseInt(button.getText().toString());
f=x+5;
button.setText(""+f);
}
else
{
x=Integer.parseInt(button.getText().toString());
f=x-5;
button.setText(""+f);
}
}
return false;
}
});
}}
【问题讨论】:
标签: java android mouseevent motionevent