1. Shreyas's Avatar
    I m creating the ButtonField & BitmapFields as

    Code:
    okButtonField = new ButtonField("Ok", BitmapField.HIGHLIGHT_SELECT | BitmapField.FOCUSABLE); 
    startBitmap = Bitmap.getBitmapResource("start.png"); 
    startBitmapField = new BitmapField(startBitmap, BitmapField.HIGHLIGHT_SELECT | BitmapField.FOCUSABLE);
    Its working with..

    Code:
    protected boolean touchEvent(TouchEvent event)
    {
    switch( event.getEvent()  ) 
    {
            case TouchEvent.DOWN:  ........
    				return true;
            case TouchEvent.MOVE: .......
                                    return true;
            case TouchEvent.UP: ........ 
                                    return true;   
    
            case TouchEvent.CLICK:
              if(deleteButton.isFocus())
              {            
                System.out.println("Touched DEL ..........");
              }
              else if(okButton.isFocus())
              {            
                System.out.println("Touched OK ..........");
              }   
    	  else if(startBitmapField.isFocus())
              {            
                System.out.println("Touched START ..........");
              }         
            return true;
    }
    return false;
    }
    but everytime the same button is invoked which is having focus.

    Means if "Ok" button is having focus then even though u clicked on "Delete" button "Ok" button is called.

    So how to change the focus on Button Click? means whichever ButtonField or BitmapField is clicked, should get the focus?

    is there any method to check "button.isClicked() like button.isFocus() " ?
    Last edited by Shreyas; 09-03-09 at 12:46 AM.
    09-03-09 12:42 AM
  2. andiamo's Avatar
    Just a small note: this is the wrong forum in which to ask this question.... this forum is more for users/consumers, you want the Developer Forum.

    In regards to your question: You want to use a FieldChangeListener to determine when the button is clicked. Don't rely on TouchEvent for this purpose, especially since it (obviously) won't work on phones other than the Storm.

    I'll try to explain instead of only providing code.

    Create a new class that implements the interface FieldChangeListener. The only method it has is fieldChanged, this is going to fire when the button is clicked, so fill it out with your code.

    Code:
    class ButtonClickListener implements FieldChangeListener
    {
         void fieldChanged(Field field, int context)
         {
              //we need to determine which button was clicked
    
              if(field.equals(deleteButton))
                   ; //delete button code goes here
              if(field.equals(okButton))
                   ; //ok button code goes here
              //you get the idea
         }
    }
    Okay, now once you've got the listener code done, you need to assign an instance of the listener to each of your buttons. In the constructor of your screen, create a new instance of your listener and then use the .setChangeListener() method of your ButtonFields to assign the listener.

    Code:
    public MyScreen()
    {
         add(deleteButton);
         add(okButton);
         //etc, add all of your buttons to the screen
    
         ButtonClickListener newListener = new ButtonClickListener();
         deleteButton.setChangeListener(newListener);
         okButton.setChangeListener(newListener);
         //etc, repeat for all of your buttons
    }
    Now each button has your listener assigned to it. When the user clicks the button, the fieldChanged method of ButtonClickListener is invoked and your app will preform the appropriate action depending on the button the user clicked.

    I hope this was able to help you.
    Last edited by Andiamo; 09-03-09 at 02:14 AM.
    09-03-09 02:10 AM
  3. Shreyas's Avatar
    Sorry I will post in related forum.

    Thanks Andiamo, I got the events....
    09-04-09 01:49 AM
LINK TO POST COPIED TO CLIPBOARD