Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified
Accepted Solution

Wrappable Button Navigation

Hi,

 

I have many buttons in my screen. Buttons are placed in a VerticalFieldManager.

 

But My problem is:

1. When the focus is in the last button, the next time I press the down key, i want to move the focus to the first button.

2. When the focus is in the first button, the next time I press the down key, i want to move the focus to the last button.

 

Can anyone suggest me something how i can do this.

 

Thanks in Advance

Bikas 

 

 

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Wrappable Button Navigation

Have you tried setting the focus on first and last button to desired button on trackball movements.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Wrappable Button Navigation

Hi,

 

I am now implementing TrackwheelListener in my code as BBDeveloper suggested.

 

Now I think the deafult Focus movement will not work and i have to implement the focus movement manuallly

in the navigationMovement(..) method.

 

I have tried to move focus manually to the next button with different stuffs but in vain.

 

Can anyone please suggest me some code to move focus to the next button or previous button.

 

This is what i have tried so far. 

 

 

import net.rim.device.api.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class TestScreen extends MainScreen implements TrackwheelListener
{
private ButtonField button1, button2, button3;
private ButtonField button4, button5;
private VerticalFieldManager mainManager;

public TestScreen()
{
mainManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);

button1 = new ButtonField("button1");
button2 = new ButtonField("button2");
button3 = new ButtonField("button3");
button4 = new ButtonField("button4");
button5 = new ButtonField("button5");

mainManager.add(button1);
mainManager.add(button2);
mainManager.add(button3);
mainManager.add(button4);
mainManager.add(button5);

this.add(mainManager);
}

public boolean trackwheelClick( int status, int time )
{
return false;
}
public boolean trackwheelUnclick( int status, int time )
{
return false;
}

public boolean trackwheelRoll(int amount, int status, int time)
{
return false;
}

public boolean navigationMovement(int dx, int dy, int status, int time)
{
//down pressed
if(dy > 0)
{
if (button5.isFocus() == true)
{
scroll(Manager.TOPMOST);
}
else
{
//have to move focus to the next lower button
}
}

//up pressed
if(dy < 0)
{
if (button1.isFocus() == true)
{
scroll(Manager.BOTTOMMOST);
}
else
{
//have to move focus to the next upper button
}
}
return true;
}
}

 

Pls help.

 

Regards 

Bikas

 

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Wrappable Button Navigation

This is workin fine...

 

 

mainManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR); button1 = new ButtonField("button1") { public boolean navigationMovement(int dx, int dy, int status, int time) { if(dy < 0) { if (button1.isFocus() == true) { button5.setFocus(); return true; } } return false; } }; button2 = new ButtonField("button2"); button3 = new ButtonField("button3"); button4 = new ButtonField("button4"); button5 = new ButtonField("button5") { public boolean navigationMovement(int dx, int dy, int status, int time) { if(dy > 0) { if (button5.isFocus() == true) { button1.setFocus(); return true; } } return false; } }; mainManager.add(button1); mainManager.add(button2); mainManager.add(button3); mainManager.add(button4); mainManager.add(button5); this.add(mainManager);

 

 

 


Use Search. "Accept Solution" If the problem is resolved.
Highlighted
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Wrappable Button Navigation

[ Edited ]

Hi BBDeveloper,

 

It worked. Smiley Happy

 

I used CustomButtonField rather than ButtonField.

Solved the problem with setFocus() method as you used.

 

 

int focusIndex = mainManager.getFieldWithFocusIndex();

 

//down pressed

Field field = mainManager.getField(focusIndex + 1);

//up pressed

//Field field = mainManager.getField(focusIndex - 1);

 

field.setFocus();

 

Thanks for the help.

 

Regards

Bikas


 

 

 

 

 

Message Edited by bikas on 05-19-2009 06:30 PM
Message Edited by bikas on 05-19-2009 06:32 PM
Message Edited by bikas on 05-19-2009 06:33 PM