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. cwg01
    Replies:
    3
    Views:
    1,198
  2. kumaranil13k
    Replies:
    4
    Views:
    473
  3. 5g Moto Android 11
    Replies:
    2
    Views:
    761
  4. Muhammad Faizan Ali Khan
    Replies:
    2
    Views:
    382
  5. App Update
    Replies:
    0
    Views:
    283
  6. Mehak Gul
    Replies:
    1
    Views:
    287
  7. ghostanime2001
    Replies:
    16
    Views:
    2,013
  8. Muhammad Faizan Ali Khan
    Replies:
    1
    Views:
    533
  9. Muhammad Faizan Ali Khan
    Replies:
    1
    Views:
    337
  10. wseng92
    Replies:
    7
    Views:
    1,561

Share This Page

Loading...