Midp2.0 introduces three layout policies:
Choice. text_wrap_on: the part that exceeds the limit is displayed in the next row.
Choice. text_wrap_off: the part that exceeds the limit is ignored.
Choice. text_wrap_default: Default policy, same as choice. text_wrap_on
The setfitpolicy and getfitpolicy methods can be used to set and obtain the current layout policy.
---------------------------------------------------------------------------
- /**
- * @ Author jcuckoo
- * @ Creation date:
- * @ Version: V 1.0
- */
- Public class fitpolicymidlet extends MIDlet implements commandlistener {
- Private display;
- Private list fitpolicylist;
- Private command offcommand;
- Private command oncommand;
- Private command defaultcommand;
- Private command exitcommand;
- Public fitpolicymidlet (){
- Display = display. getdisplay (this );
- // Create a list
- Fitpolicylist = new list ("fitpolicy layout policy test", choice. implicit );
- // Add Option
- Fitpolicylist. append ("test the fitpolicy layout policy. By default, text that exceeds the screen width is displayed with a line break. ", Null );
- // Initialize four buttons
- Offcommand = new command ("wrap_off", command. screen, 1 );
- Oncommand = new command ("wrap_on", command. screen, 1 );
- Defaultcommand = new command ("wrap_default", command. screen, 1 );
- Exitcommand = new command ("exit", command. Exit, 1 );
- // Add the button to the list
- Fitpolicylist. addcommand (offcommand );
- Fitpolicylist. addcommand (oncommand );
- Fitpolicylist. addcommand (defaultcommand );
- Fitpolicylist. addcommand (exitcommand );
- // Register the listener
- Fitpolicylist. setcommandlistener (this );
- }
- Protected void destroyapp (Boolean arg0 ){
- }
- Protected void pauseapp (){
- }
- Protected void Startapp () throws midletstatechangeexception {
- Display. setcurrent (fitpolicylist );
- }
- Public void commandaction (command C, displayable d ){
- // Convert the passed displayable object type to the list type for subsequent operations
- List list = (list) D;
- // Determine whether there is only one option. If there are more than one option, delete it.
- If (list. Size ()> 1 ){
- List. Delete (1 );
- }
- // Set the layout policy according to the selection button and add the prompt information to the list.
- If (C = offcommand ){
- List. setfitpolicy (choice. text_wrap_off );
- List. append ("your current layout policy is: text_wrap_off", null );
- }
- If (C = oncommand ){
- List. setfitpolicy (choice. text_wrap_on );
- List. append ("your current layout policy is: text_wrap_on", null );
- }
- If (C = defaultcommand ){
- List. setfitpolicy (choice. text_wrap_default );
- List. append ("your current layout policy is text_wrap_default", null );
- } If (C = exitcommand ){
- Destroyapp (false );
- Yydestroyed ();
- }
- /* String STR = "your current layout policy is :";
- Int result = fitpolicylist. getfitpolicy ();
- Switch (result ){
- Case 0:
- STR = STR + "text_wrap_default ";
- Break;
- Case 1:
- STR = STR + "text_wrap_on ";
- Break;
- Case 2:
- STR = STR + "text_wrap_off ";
- }
- System. Out. println (STR );*/
- }
- }