List layout policy (fitpolicy)

Source: Internet
Author: User

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.

---------------------------------------------------------------------------

  1. /**
  2. * @ Author jcuckoo
  3. * @ Creation date:
  4. * @ Version: V 1.0
  5. */
  6. Public class fitpolicymidlet extends MIDlet implements commandlistener {
  7. Private display;
  8. Private list fitpolicylist;
  9. Private command offcommand;
  10. Private command oncommand;
  11. Private command defaultcommand;
  12. Private command exitcommand;
  13. Public fitpolicymidlet (){
  14. Display = display. getdisplay (this );
  15. // Create a list
  16. Fitpolicylist = new list ("fitpolicy layout policy test", choice. implicit );
  17. // Add Option
  18. Fitpolicylist. append ("test the fitpolicy layout policy. By default, text that exceeds the screen width is displayed with a line break. ", Null );
  19. // Initialize four buttons
  20. Offcommand = new command ("wrap_off", command. screen, 1 );
  21. Oncommand = new command ("wrap_on", command. screen, 1 );
  22. Defaultcommand = new command ("wrap_default", command. screen, 1 );
  23. Exitcommand = new command ("exit", command. Exit, 1 );
  24. // Add the button to the list
  25. Fitpolicylist. addcommand (offcommand );
  26. Fitpolicylist. addcommand (oncommand );
  27. Fitpolicylist. addcommand (defaultcommand );
  28. Fitpolicylist. addcommand (exitcommand );
  29. // Register the listener
  30. Fitpolicylist. setcommandlistener (this );
  31. }
  32. Protected void destroyapp (Boolean arg0 ){
  33. }
  34. Protected void pauseapp (){
  35. }
  36. Protected void Startapp () throws midletstatechangeexception {
  37. Display. setcurrent (fitpolicylist );
  38. }
  39. Public void commandaction (command C, displayable d ){
  40. // Convert the passed displayable object type to the list type for subsequent operations
  41. List list = (list) D;
  42. // Determine whether there is only one option. If there are more than one option, delete it.
  43. If (list. Size ()> 1 ){
  44. List. Delete (1 );
  45. }
  46. // Set the layout policy according to the selection button and add the prompt information to the list.
  47. If (C = offcommand ){
  48. List. setfitpolicy (choice. text_wrap_off );
  49. List. append ("your current layout policy is: text_wrap_off", null );
  50. }
  51. If (C = oncommand ){
  52. List. setfitpolicy (choice. text_wrap_on );
  53. List. append ("your current layout policy is: text_wrap_on", null );
  54. }
  55. If (C = defaultcommand ){
  56. List. setfitpolicy (choice. text_wrap_default );
  57. List. append ("your current layout policy is text_wrap_default", null );
  58. } If (C = exitcommand ){
  59. Destroyapp (false );
  60. Yydestroyed ();
  61. }
  62. /* String STR = "your current layout policy is :";
  63. Int result = fitpolicylist. getfitpolicy ();
  64. Switch (result ){
  65. Case 0:
  66. STR = STR + "text_wrap_default ";
  67. Break;
  68. Case 1:
  69. STR = STR + "text_wrap_on ";
  70. Break;
  71. Case 2:
  72. STR = STR + "text_wrap_off ";
  73. }
  74. System. Out. println (STR );*/
  75. }
  76. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.