How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm ?
- 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);
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; }
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 AMLike 0 - 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 } }
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 }
I hope this was able to help you.Last edited by Andiamo; 09-03-09 at 02:14 AM.
09-03-09 02:10 AMLike 0
- Forum
- BlackBerry OS Phone Forums
- More BlackBerry Phones
- BlackBerry Storm Series
How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm ?
LINK TO POST COPIED TO CLIPBOARD