Create combobox without XML


Last Updated:

  1. IORI999

    IORI999 New Member This Topic's Starter

    Joined:
    Dec 10, 2009
    Messages:
    1
    Likes Received:
    0
    How can I create a combobox programmatically without using XML?
     

    Advertisement
  2. trackaroo

    trackaroo Member

    Joined:
    Dec 12, 2009
    Messages:
    8
    Likes Received:
    0
    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...