This article will focus on the implementation of Tabbed Pane similar to Lwuit in the Development of Black Berry. Although Lwuit has the version of Black Berry, it combines different system versions of all versions, including QWERTY, suretype, and touch, to make cropping very difficult.
BlackBerry Development achieves TabbedPane effect similar to Lwuit
Although Lwuit has a version developed by BlackBerry, after analyzing its source code, it is found that it cannot be directly applied to actual projects, it combines different system versions of all versions, including QWERTY, suretype, and touch, to make cropping very difficult. The current design structure is not very clear, so the source code cropping process is chaotic. Although blackberryUI does not provide paging effects similar to Lwuit, we can use the existing API to perform simple imitation. Wait for some difficult problems to solve, and then study them slowly...
Two implementation methods:
1. Use Screen switching;
2. Use Graphics encapsulation.
Both methods use the navigationMovement () Event Response Function of the scroll wheel. Therefore, you must rewrite the event on the screen to be switched.
◆ Implementation 1: use Screen Switching
Idea: First press the two screens into the stack in the constructor of UiApplication. Then create two Sreen and rewrite the navigationMovement () method in each Screen. Obtain the UiApplication object in navigationMovement () and call UiApplication. pushScreen () to push another interface to the stack. In another interface, call UiApplication. popScreen () to bring up the stack.
Code in the first screen:
- Viewplaincopytoclipboardprint?
- /*
- * Scroll event response
- * Scroll wheel action: upward dy =-1, downward dy = 1, left dx =-1, right dx = 1
- * @ Seenet. rim. device. api. ui. Screen # navigationMovement (int, int)
- */
- ProtectedbooleannavigationMovement (intdx, intdy, intstatus, inttime ){
- // Dialog. alert ("TrackBallmoved: \ r \ n" + "x:" + dx + "\ r \ ny:" + dy );
- If (dx> 0 & this. isDisplayed ()){
- SillyDowntheApp = (SillyDown) this. getApplication ();
- TheApp. popScreen (theApp. getFirstScreen ());
- Returntrue;
- }
- Returnfalse;
- }
- /*
- * Scroll event response
- * Scroll wheel action: upward dy =-1, downward dy = 1, left dx =-1, right dx = 1
- * @ Seenet. rim. device. api. ui. Screen # navigationMovement (int, int)
- */
- ProtectedbooleannavigationMovement (intdx, intdy, intstatus, inttime ){
- // Dialog. alert ("TrackBallmoved: \ r \ n" + "x:" + dx + "\ r \ ny:" + dy );
- If (dx> 0 & this. isDisplayed ()){
- SillyDowntheApp = (SillyDown) this. getApplication ();
- TheApp. popScreen (theApp. getFirstScreen ());
- Returntrue;
- }
- Returnfalse;
- }
-
- Code in the second screen:
-
- Viewplaincopytoclipboardprint?
- /*
- * Scroll event response
- * Scroll wheel action: upward dy =-1, downward dy = 1, left dx =-1, right dx = 1
- * @ Seenet. rim. device. api. ui. Screen # navigationMovement (int, int)
- */
- ProtectedbooleannavigationMovement (intdx, intdy, intstatus, inttime ){
- // TODOAuto-generatedmethodstub
- If (dx <0 & this. isDisplayed ()){
- SillyDowntheApp = (SillyDown) this. getApplication ();
- TheApp. pushScreen (theApp. getFirstScreen ());
- Returntrue;
- }
- Returnfalse;
- }
- /*
- * Scroll event response
- * Scroll wheel action: upward dy =-1, downward dy = 1, left dx =-1, right dx = 1
- * @ Seenet. rim. device. api. ui. Screen # navigationMovement (int, int)
- */
- ProtectedbooleannavigationMovement (intdx, intdy, intstatus, inttime ){
- // TODOAuto-generatedmethodstub
- If (dx <0 & this. isDisplayed ()){
- SillyDowntheApp = (SillyDown) this. getApplication ();
- TheApp. pushScreen (theApp. getFirstScreen ());
- Returntrue;
- }
- Returnfalse;
- }
Comment: This implementation method is relatively simple, but the effect is average.
◆ Implementation 2: Graphics Encapsulation
Idea: use Graphics to encapsulate a LabelField and then redraw each Field in the navigationMovement () method.
Code: writing. Mark it first)
Comment: You can use this method to encapsulate a TabbedPane. You can set the UI color, width, height, and font. The interface is gorgeous, but the code is complicated.