Bada development overview: Use of controls

Source: Internet
Author: User

Unless otherwise specified, the following examples are based on bada SDK 1.0.0.

1. Image Loading Function

 
  1. Osp::Graphics::Bitmap*
  2.  
  3. BaseForm::GetBitmapN(const Osp::Base::String& name)
  4.  
  5. {
  6.  
  7.     Bitmap* pBitmap = null;
  8.  
  9.     Image* pImage = new Image();
  10.  
  11.     String fullname(L"/Res/");
  12.  
  13.     fullname.Append(name);
  14.  
  15.     pImage->Construct();
  16.  
  17.     if(fullname.EndsWith(L"jpg"))
  18.  
  19.     {
  20.  
  21.         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);  
  22.  
  23.     }
  24.  
  25.     else if(fullname.EndsWith(L"bmp"))  
  26.  
  27.     {  
  28.  
  29.         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);  
  30.  
  31.     }
  32.  
  33.     else if(fullname.EndsWith(L"png"))  
  34.  
  35.     {  
  36.  
  37.         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_ARGB8888);
  38.  
  39.     }  
  40.  
  41.     else if (fullname.EndsWith(L"gif"))  
  42.  
  43.     {  
  44.  
  45.         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
  46.  
  47.     }  
  48.  
  49.     delete pImage;  
  50.  
  51.     return pBitmap;  
  52.  
  53. } 

2. Button

I have set the background image of the button. The example is as follows:

 
  1. Osp::Graphics::Bitmap *__pReturn;  
  2.  
  3. Osp::Graphics::Bitmap *__pReturnAct;  
  4.  
  5.  
  6. static const int ID_BUTTON_RETURN = 100;  
  7.  
  8. __pReturn = GetBitmapN(L"return.png");
  9.  
  10. __pReturnAct = GetBitmapN(L"returnact.png");  
  11.  
  12.     Button *pBtnReturn = new Button();  
  13.  
  14. pBtnReturn->Construct(Rectangle(x, y, w, h), "");
  15.  
  16. pBtnReturn->SetActionId(ID_BUTTON_RETURN);
  17.  
  18. pBtnReturn->SetNormalBackgroundBitmap(*__pReturn);
  19.  
  20. pBtnReturn->SetPressedBackgroundBitmap(*__pReturnAct);  
  21.  
  22. pBtnReturn->AddActionEventListener(*this);
  23.  
  24. AddControl(*pBtnReturn);  
  25.  
  26. delete __pReturn;  
  27.  
  28. delete __pReturnAct; 

3. EditField

 
  1. Osp: Ui: Controls: EditField * _ pAddrEdit;
  2.  
  3. _ PAddrEdit = new EditField ();
  4.  
  5. // The second parameter can be selected based on the text, and the maximum length of the text can be customized.
  6.  
  7. _ PAddrEdit-> Construct (Rectangle (x, y, w, h), EDIT_FIELD_STYLE_URL_SMALL, INPUT_STYLE_FULLSCREEN, false, 300 );
  8.  
  9. AddControl (* _ pAddrEdit );
  10.  
  11. _ PAddrEdit-> SetEnabled (true );
  12.  
  13. _ PAddrEdit-> SetKeypadEnabled (true );
  14.  
  15. _ PAddrEdit-> SetText (L "http ://");

4. CheckButton

 
  1. CheckButton *pCheckBtn = new CheckButton();  
  2.  
  3.         pCheckBtn->Construct(Rectangle(x, y, dx, dy),CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE, false, "");   
  4.  
  5.         pCheckBtn->SetActionId(ID_CHECK_BTN_ON, ID_CHECK_BTN_OFF);  
  6.  
  7.         pCheckBtn->SetTextHorizontalAlignment(ALIGNMENT_LEFT); pCheck3G->AddActionEventListener(*this);         AddControl(*pCheckBtn); 

5. RadioGroup

 
  1. CheckButton *pCheckWap = new CheckButton();
  2.  
  3. pCheckWap->Construct(Rectangle(x, y, w, h), CHECK_BUTTON_STYLE_RADIO, BACKGROUND_STYLE_NONE, false, L"wap");
  4.  
  5. pCheckWap->SetActionId(ID_BUTTON_RADIOWAP_ON, ID_BUTTON_RADIOWAP_OFF);
  6.  
  7. pCheckWap->AddActionEventListener(*this);  
  8.  
  9. AddControl(*pCheckWap);  
  10.  
  11. CheckButton *pCheckNet = new CheckButton();  
  12.  
  13. pCheckNet->Construct(Rectangle(x, y, w, h),CHECK_BUTTON_STYLE_RADIO, BACKGROUND_STYLE_NONE, false, L"net");  
  14.  
  15. pCheckNet->SetActionId(ID_BUTTON_RADIONET_ON, ID_BUTTON_RADIONET_OFF);  
  16.  
  17. pCheckNet->AddActionEventListener(*this);  
  18.  
  19. AddControl(*pCheckNet);  
  20.  
  21. RadioGroup *pRadioGroup = new RadioGroup();
  22.  
  23. pRadioGroup->Construct();  
  24.  
  25. pRadioGroup->Add(*pCheckWap);  
  26.  
  27. pRadioGroup->Add(*pCheckNet);  
  28.  
  29. pRadioGroup->SetSelectedItem(*pCheckNet);  
  30.  
  31. AddControl(*pRadioGroup); 

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.