1. Check out our app, Forums for Android! Download and leave feedback here!

Create combobox without XML

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

  1. IORI999

    IORI999 New Member
    Thread Starter
    5

    Dec 10, 2009
    1
    0
    5
    How can I create a combobox programmatically without using XML?
     

    Advertisement

  2. trackaroo

    trackaroo Member
    5

    Dec 12, 2009
    8
    0
    5
    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
     

Share This Page

Loading...