Hey Avigadl,

If I change the values of the each direction like DIRECTION_TOP = 0,
DIRECTION_DOWN = 1, DIRECTION_RIGHT = 2, DIRECTION_LEFT = 3; it is working?

I changed that but unfortunetly its not working.
Any other Solution?

On Fri, Sep 3, 2010 at 5:26 PM, avigadl <avig...@gmail.com> wrote:

> Several suggestions:
> 1. Note that all the directions has value 0, this might be a poblem
> wen you want to distinguish between directions. You have to set  a
> unique value to eac direction.
> 2. We suggest to use switch case statement instead of if else if.
>
> Hope this helps.
>
>
>
> On Sep 3, 12:35 pm, dhrumil <dhrumilsh...@gmail.com> wrote:
> > Hello 2All,
> >
> > I have a problem in handling my ball using D-Pad control.
> >
> > Here is my code of handling a ball.
> >
> > public static final int DIRECTION_RIGHT = 0, DIRECTION_UP = 0,
> > DIRECTION_DOWN = 0, DIRECTION_LEFT = 0;
> > private int direction = 0;
> > protected volatile boolean running = true;
> > public boolean onKeyDown(int KeyCode, KeyEvent event){
> >         if(KeyCode==KeyEvent.KEYCODE_DPAD_CENTER){
> >
> >                         if(running == true){
> >
> >                         if(KeyCode == KeyEvent.KEYCODE_DPAD_RIGHT){
> >                         setDirection(DIRECTION_RIGHT);
> >                 }
> >                 else if(KeyCode == KeyEvent.KEYCODE_DPAD_DOWN){
> >                         setDirection(DIRECTION_DOWN);
> >                 }
> >                 else if(KeyCode == KeyEvent.KEYCODE_DPAD_LEFT){
> >                         setDirection(DIRECTION_LEFT);
> >                 }
> >         }
> >         }
> >         else {
> >                 running = false;
> >         }
> >
> >         return true;
> >     }
> >
> >         public void setDirection(int direction) {
> >                 this.direction = direction;
> >         }
> >
> >         public int getDirection() {
> >                 return direction;
> >         }
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to