I need focusable horizontal field manager,for this i found some code in forums.
hfm[i]=new HorizontalFieldManager(HorizontalFieldManager.FOCUSABLE)
{
protected void onFocus(int direction)
{
Background bg = BackgroundFactory.createLinearGradientBackground(0x00E2E2E2,0x00E2E2E2,0x00E2E2E2,0x00E2E2E2);
setBackground(bg);
}
protected void onUnfocus()
{
Background bg = BackgroundFactory.createLinearGradientBackground(0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,0x00FFFFFF);
setBackground(bg);
}
};
rtf[i]=new ExtendedLabel(list[i]);
hfm[i].add(rtf[i]);
add(hfm[i]);
But the it is not focusable,if it
You should also add this method to your new HorizontalFieldManager
public boolean isFocusable(){
return true;
}
Remember though when you set a manager to be focusable in this way it must have a field within it that is focusable or else you will get a null exception when the screen tries to give your managae focus.
This is a known problem that happens to everyone at least one time.
I started a topic in BB support forum:
Scroll happening but Vertical Field Manager Not Moving
And the answer given was the blackberry support forum article:
My scrollable manager is not scrolling
That is not a real answer but is the only workaround that's available for the moment
Another posible solution to this is:
A friend gave me the solution... you can put your manager into an
horizontal manager and then you can just add an nullfield with a
focusable behaviour, This will do the trick
You can try that.
You give focus to this.
rtf[i]=new ExtendedLabel(list[i]);
as....
rtf[i]=new ExtendedLabel(list[i],Field.Focusable);
Related
I am having trouble with vertical scrolling on a blackberry app.
it works just fine on touch screens, but when scrolling using a track pad, it jumps from being at the top position to being at the bottom position.
Anyone had a similar problem? any idea what i could try?
Here is a snippet from my code. i have a static background image and the fields scroll on top of it:
vertical_main = new VerticalFieldManager(USE_ALL_WIDTH |NO_VERTICAL_SCROLL |USE_ALL_HEIGHT);
vertical_AllTags=new VerticalFieldManager(USE_ALL_WIDTH | VERTICAL_SCROLL);
// i then add all the fields to vertical_AllTags
vertical_main.add(vertical_AllTags);
vertical_main.invalidate();
add(vertical_main);
thanks in advance for your help
EDIT:
The suggestion of giving each field focus was correct. the only other part that needs to be done is when you override the onFocus method for a field, you need to call the super() function so that all the other normal parts of the onFocus method are still called:
protected void onFocus(int direction) {
text_select=true;
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
text_select=false;
invalidate();
super.onUnfocus();
}
Thank you so much.
This is common issue in non touch devises for beginners.
if you want to scroll field by field there is two ways
1) you need to give the focus to all fields then it will come field by
field focus down
another way is means you dont need to focus on each and every field
2)just add the NullField after your every field and give focus to all
NullFields then your trackball will bring your screen field by field
This happends beacuse in TrackWheel Scrolling it scrolls up to the next Focused field. I think you are not give any focus between the vertical_AllTags.
You can solved this by using NullField() class. Like...
add(new NullField(Field.FOCUSABLE))
when you add add(new NullField(Field.FOCUSABLE)); you will get the null focus which is not know by you. And you can navigate all the fields like Touch Screen.
You can solve that issue by adding two vertical field manager.. take a look at the code in this post
how could i create a custom ButtonField with no border in Blackberry...
any help will be appreciated
bingo, just add the applyTheme() method
class BitmapButtonField extends ButtonField {
protected void applyTheme()
{
}
}
Arhimed & Rafael, thanks for you help!
Use this tutorial to create your own custom field.
Control the appearance of your field in paint() method.
Yes, this is possible by extending Field. You just need to create 2 images (one for a focused state and one for an unfocused state). Just don't draw the border on those images.
A sample implementation can be found here.
As Arhimed said, you should extend Field. This will give you the maximum amount of customization over how the button looks.
Here's an example of a customizable button I've created: https://github.com/HeshamMegid/BlackBerry-Custom-Controls
You could use it as it is or modify the code further to suit your needs.
I have developed a application with considering touch screen device for BlackBerry.
But when I am trying to use it in Non touch screen device all the lable also shows the focus.
Basically what I want that LabelField should not show any focus.
I have set NonFocusable Property for it but still it is not working.
Please help me out.
Thanks in advance...
You dont want the LabelField to have focus when you select it on touchscreen ?
Extend LabelField and override onFocus like so -
protected void onFocus(int direction) {
}
Also try overriding the LabelField's isFocusable() to always return false. It's possible that the GFM is just calling setFocus() on the next field without checking whether or not it can actually accept focus. If this is the case you may have to override the GFM's nextFocus() method and correct the logic.
I am developing an app which supposed to work on devices that have OS 4.5 or later. In my application I need to know when the virtual keyboard is visible or invisible. Because if virtual keyboard is visible, the text area which the user is supposed to type in is behind the keyboard. If I could determine the moment of virtual keyboards state changed, I could refresh the screen and move the text area upper location.
Is there a way to do that?
Edit: the next button is at the status panel. The edit field is at the custom horizontal field manager.
When I touch the edit field, the virtual keyboard opens and the contents of the edit field is lost.
There is no way to do that with the same code. You need to divide your code in two. One of them handles 4.5 - 4.7. The other handles 4.7 and later.
You can add a keyboard listener to 4.7 (and later) code that should check whether the screen changes in a continuous thread. It is not good, but it can work.
You have two choices. The first choice is better:
Figure out an invariant that works with the keyboard visible or hidden. The screen layout method is invoked when the visibility state of the keyboard changes, and the vertical size is reduced for a visible keyboard. If your invariants take advantage of that then you can just implement the logic in the screen layout method.
In this case, I would suggest a layout method that always keeps the 'next' button at the bottom of the screen, and puts the username textbox in the center of the remaining space.
Use conditional compilation so you can write code that makes reference to the VirtualKeyboard class on OS 4.7+, and that code goes away in the older BlackBerry releases. 4 July: by conditional compilation, I mean use the BlackBerry preprocessor.
There is no event for this, but you can determine current state of virtual keyboard and set required state.
For example hide it
if(VirtualKeyboard.isSupported() == true){
VirtualKeyboard keyboard = getVirtualKeyboard();
if(keyboard != null)
keyboard.setVisibility(VirtualKeyboard.HIDE);
}
It is a quite challenging job. However, I believe there is no direct API or way to determine the virtual Keyboard state. The only way is to override the setLayout() method and determine if the screen width and height has been changed. And also you need to check the GUI layouts of your screen.
Set the VERTICAL_SCROLL style for the Manager which holds the EditField, or you can use a Screen with VERTICAL_SCROLL style. Doing this, the EditField automatically scrolls when the keyboard is displayed.
Use following class, maybe this is helpful for you:
class FocusableManager extends MainScreen implements FocusChangeListener
{
private BasicEditField b;
public FocusableManager()
{
VerticalFieldManager vfm=new VerticalFieldManager(VERTICAL_SCROLL);
vfm.add(new ButtonField("first"));
b=new BasicEditField();
b.setFocusListener(this);
vfm.add(b);
vfm.add(new ButtonField("second"));
vfm.setMargin(250,0,0,0);
add(vfm);
}
public void focusChanged(Field field, int eventType)
{
if(field==b)
{
if(eventType==1)//when edit field gain focus
{
VirtualKeyboard virtKbd;
virtKbd = getScreen().getVirtualKeyboard();
virtKbd.setVisibility(VirtualKeyboard.SHOW_FORCE);
}
else if(eventType==3)//when edit field lost focus
{
VirtualKeyboard virtKbd;
virtKbd = getScreen().getVirtualKeyboard();
virtKbd.setVisibility(VirtualKeyboard.HIDE_FORCE);
}
}
}
}
I'm running into the following scenario on some devices: when the use clicks on field and expects an response, instead of properly responding to that click event, the device shows the context menu at the bottom center of the screen.
navigationUnclick and trackwheelUnclick
From what I've read, I can override navigationUnclick and trackwheelUnclick to prevent the menu from showing. I'm doing this as the screen level but reproducing the centered-menu scenario is difficult. Is this the correct approch?
Why does this happen? Is there any way to resolve this?
I recently had this happening. I was extending MainScreen to provide some basic functionality, but didn't want the context menus. Returning true from navigationClick() removed this behavior.
public class MyScreen extends MainScreen {
protected boolean navigationClick(int status, int time) {
/*
... custom behavior ...
*/
return true;
// the following line would trigger the context menu
//return super.navigationClick(status, time);
}
}
I didn't need to override navigationUnclick() at all. Unlike #JustinD's approach with override onMenu(), this only prevents the menu from this certain case -- not across the entire screen (which you may want, and that would probably be a better way to do it).
Anyway, that's been my experience with clicks and menus recently.
Can you post your code? Try overriding trackwheelClick and navigationClick instead of the Unlick methods. Also make sure you return true in these methods.
If you override onMenu and just return true (you handled the menu event) then the menu will not show up...assuming you don't need a full menu either - if you want full menu and not context menu then just do what Jan said and you should be fine - make sure to return true or else the event will bubble up and end up with the menu being generated
public class MyClass Extends MainScreen
{
///
// Override onMenu to prevent menu from coming up when you click trackwheel
public boolean onMenu(int instance)
{
return true;
}
}
You could use CONSUME_CLICK style on all Fields in your MainScreen...