Blackberry Button not working in HorizontalFieldManager - blackberry

My workFlow is like this ... I have taken Three HoriZontalManager one for holding theBackgroundImage of the button and two HoriZontalManager to hold the CustomButton and i am adding the main hfm which hold the button and the background image at top and then i have added the list in a VerticalfieldManager but i dont get the button Working the focus always remains on the list Field. Now when I click on the Button the focus always resides on the First row of the list Field so it always show me the picker which is actually i have implemented on the first row of listfield. How can i Solve it ..
Thanks in Advanced..
Please help.

I have solved This issue ... I had to check that if the focus is on the button then do my work else the list field will be invoked and it solved the issue. And it works for touchScreen simulator as well as trackpad devices.
protected boolean navigationClick(int status, int time) {
// if the row select do something with it
// for first row which is time
if(backCustomButton.isFocus()) {
UiApplication.getUiApplication().pushScreen(new saveScreen());
}else if (saveCustomButton.isFocus()) {
Dialog.inform("Save Button on focus");
}else
if (_list.getSelectedIndex() == 0){
// Do the ListSpecific things
}

Related

Touch Event Blackberry Triggered Multiple Times

I'm working with the Blackberry Touch Event and I need to process the TouchEvent.MOVE, TouchEvent.UP and TouchEvent.DOWN to move a carousel of images and the TouchEvent.CLICK to generate some specific action.
My problem is that the touchEvent() method is being called several times. How can I prevent this? Because the behaviour is getting all messed up.
For example: when I just want to capture the TouchEvent.CLICK event, the UP-DOWN-MOVE-CLICK are being triggered one after the next.
My code does the following:
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
//CHANGE THE CONTENT OF A FIELD
return true;
} else if ((message.getEvent() == TouchEvent.MOVE)
|| (message.getEvent() == TouchEvent.UP)
|| (message.getEvent() == TouchEvent.DOWN)) {
//DELETE THE FIELD
//MOVE A CAROUSEL OF IMAGES
} else {
return false;
}
}
public void moverTouch(int dx) {
//ADD THE FIELD PREVIOUSLY DELETED
}
As you can see, when the CLICK event is captured, I need to change the content of a field, but when the MOVE or UP or DOWN event is captured, I need to delete that Field from his manager, do some working with a carousel of images, and then re-add the field previously deleted.
The carousel moving part works fine, but when I try to capture JUST the CLICK event, and the others are being triggered as well, but the moverTouch() function doesn't get triggered because there is no actual movement on the carousel of images, I end up with a deleted field that I need to update its content.
At a glance:
I think you need to differentiate touch gestures (I believe you are "listening" for something like a swipe gesture to scroll the gallery image) from "normal" touch events (specifically you need to process TouchEvent.CLICK to apply "some specific action" to the clicked image).
To decide whether the TouchEvent represents a gesture there is a TouchEvent.GESTURE constant. Then it is possible to know what exactly TouchGesture it represents by calling TouchEvent.getGesture().
Some sample code for touch gestures can be viewed here.

Trackwheel Click Event Issue

I am dealing with KeywordFilterField which is populated with the list of the countries. Now the problem i am facing is that when i click the particular country it should move to the next screen as I have written the pushScreen code in the trackwheelClick event after checking that _keywordFilterField is focusable or not, but this is not the case. The Menu opens when trackwheelClick event is fired, at the center of the screen, rather than moving onto the next screen.Can anybody have the idea why Menu dialog opens on the trackwheelclick event instead of going to the next screen.
See what i have done on trackwheel click event:
protected boolean trackwheelClick(int status, int time) {
if (_keywordFilterField.isFocus()) {
int index = _keywordFilterField.getSelectedIndex();
ReadableList readableList = _keywordFilterField.getResultList();
Object selectedCountry = readableList.getAt(index);
String countryName=selectedCountry.toString();
urlutf8Encoder=new URLUTF8Encoder();
String newCountry=urlutf8Encoder.encode(countryName);
pushToSearchResult(newCountry,countryName);//To Next SCreen
return true;
}
return false;
}
But it looks like:
The trackwheelClick event returns a boolean that indicates whether the event is consumed. Once an event is consumed, it stops propagating to other UI elements. If you return true, the menu will stop appearing.

Custom List Field with Custom ObjectChoiceField in blackberry?

I am a new BB developer working on android simultaneously, I am preparing a project containing list and object choice fields in both the languages.
In blackberry, I have a list of 10 elements and on each element row I need to show an arrow button on click of that button a ObjectChoiceField will pops up.
Here, it is clear that the list and obejctchoice field both are custom.
I am very confused please let me know, how this can be achieved.
Thanx in advance..!:|
// customize ListField
How to customize a ListField in BlackBerry?
To get clicked item just add below function to code
protected boolean navigationClick(int status, int time) {
Field field = this.getLeafFieldWithFocus();
if(field instanceof ListField){
System.out.println("navigationClick Yes Yes you clicked list item ");
ListField listField = (ListField)field;
// this will give you clicked index.
int index = listField.getSelectedIndex();
// pop up your Object choice field here...
}
return true;
}

ListField and button focus issue in same screen

Hello all i stuck at one problem. I have implemented a ListField in one Screen. On top of the Screen i have used one HorizontalFieldManager to hold a TitleLabel and Two Butons. I have pushed some screen on all the rows of the listfield. My problem is, letSuppose when i am on 4th row and i have selected what i want then when i clicking on the button, then the button worked but the screen which i have implemented at 4th row also appear how to avoid it. I am testing it on storm 9550 simulator and using Blackberry eclipse plugin5.0 . I am running out of idea please help me .
navigation click is like this
protected boolean navigationClick(int status, int time) {
selectListAndButton();
return true;
}
//And here is the selectListAndButton Method
private selectListAndButton(){
Field field = getFieldWithFocus().getLeafFieldWithFocus();
if(field == backCustomButton){
//Popped the active Screen
}else if(field == saveCustomButton){
//Saving some Data to the Database And pushing another Screen here
// problem comes here if i am at 2nd row of the listfield and selects
something from there and clicked on the button the screen which was
implemented at 2nd row also appears
}
else if (_list.getSelectedIndex() == 0){
//Called a date picker
}
else if (_list.getSelectedIndex() == 1){
//Pushed some another screen
}
else if (_list.getSelectedIndex() == ){
//Pushed some another screen
}
You need to override onTouch for Screen and call specific functionality depend on event coordinates and Field boundaries:
protected boolean touchEvent(TouchEvent message) {
if (isTouchInside(message, saveCustomButton)) {
save();
} else {
showNextScreen();
}
}
private boolean isTouchInside(TouchEvent messages, Field field) {
int eventCode = message.getEvent();
int touchX = message.getX(1);
int touchY = message.getY(1);
XYRect rect = field.getContentRect();
return rect.contains(touchX, touchY);
}
I had solved it. but posting the answer late. I just dropped the idea of using ListField because i dont have so much rows to add. So i have just used the little trick rather using ListField i have used HorizontalFieldManager and its look like a List so everything working fine.
Thanks cheers :)

hiding menu on click

I am using NullField() in one of my screen so that the default focus should not be on any of the button . but when i am clicking on the screen where no field is there , menu screen is being displayed. i dont want that menu screen to be poped up tough it should open when i click menu button.
Thanks alot
override method.
protected boolean navigationClick(int status, int time) {
Field focus = UiApplication.getUiApplication().getActiveScreen()
.getLeafFieldWithFocus();
if (focus instanceof NullField) {
return true;
}
return super.navigationClick(status, time);
}
Note:This code is only for giving you hint.

Resources