1. Are you ready for the Galaxy S20? Here is everything we know so far!

Create combobox without XML

Discussion in 'Android Development' started by IORI999, Dec 10, 2009.

  1. IORI999

    IORI999 Lurker
    Thread Starter

    How can I create a combobox programmatically without using XML?
     



    1. Download the Forums for Android™ app!


      Download

       
  2. trackaroo

    trackaroo Lurker

    Check out the Spinner class.

    Code (Text):
    1.  
    2. //spinner view
    3. RelativeLayout.LayoutParams spinnerParams =
    4.     new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    5. spinnerParams.setMargins(1, 1, 1, 1);
    6. spinnerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    7.  
    8. spinnerValueView = new Spinner(context);
    9. ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, optionsStr);          
    10. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);                    
    11. spinnerValueView.setAdapter(adapter);  
    12. spinnerValueView.setSelection(selected, true);
    13. spinnerValueView.setOnItemSelectedListener(this);
    14. nameValueLayout.addView(spinnerValueView, spinnerParams);
    Jeff
     
Loading...
Similar Threads - Create combobox without
  1. Senthil Kumar P
    Replies:
    2
    Views:
    315
  2. nullshxt
    Replies:
    3
    Views:
    274
  3. Samsung
    Replies:
    0
    Views:
    228
  4. Chen Dol Dawd
    Replies:
    1
    Views:
    246
  5. chethan1703
    Replies:
    0
    Views:
    279
  6. dorlow
    Replies:
    3
    Views:
    341
  7. Kayleigh Blue
    Replies:
    3
    Views:
    346
  8. Rhemsuda
    Replies:
    2
    Views:
    731
  9. matthewpederson
    Replies:
    0
    Views:
    484
  10. Dan Coleman
    Replies:
    0
    Views:
    482

Share This Page

Loading...