开发者

Android - Array or for statement problem

开发者 https://www.devze.com 2022-12-25 07:56 出处:网络
I making on a app, but I have a problem with for or with a array. When I use this code Button Button[] = {(Button)findViewById(R.id.button01), (Button)findVi开发者_如何转开发ewById(R.id.button02), (B

I making on a app, but I have a problem with for or with a array. When I use this code

Button Button[] = {(Button)findViewById(R.id.button01), (Button)findVi开发者_如何转开发ewById(R.id.button02), (Button)findViewById(R.id.button03),(Button)findViewById(R.id.button04)};

...

case MotionEvent.ACTION_MOVE:
  for (int i = 0; i < Button.length; i++) {
   if (Y > Button[i].getTop()+25 && Y < Button[i].getBottom()+25 && X > Button[i].getLeft() && X < Button[i].getRight()){
    LastButton = i;
    edittext.setText("id " + i);
   }
  }
break;

But the for statement skip the first button in the array and the second button get id 1. anyone know how I can fix it? Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号