使用接口Adapter 下拉列表

<string-array name="feets">
     <item>2 Feet</item>
     <item>3 Feet</item>
     <item>4 Feet</item>
     <item>5 Feet</item>
     <item>6 Feet</item>
     <item>7 Feet</item>
     <item>8 Feet</item>
 </string-array>

 

android:prompt="@string/feet_prompt"
public class Abmi extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        findViews();

        setListeners();    
    }

private Spinner field_feet;


private void findViews()
{
   

    field_feet=(Spinner)findViewById(R.id.feet);


     ArrayAdapter<CharSequence> adapter_feet=ArrayAdapter.createFromResource(this, R.array.feets, android.R.layout.simple_spinner_item);
     adapter_feet.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     field_feet.setAdapter(adapter_feet);
}


private void setListeners()
{
    field_feet.setOnItemSelectedListener(getFeet);
}

private int feet;

private Spinner.OnItemSelectedListener getFeet = new Spinner.OnItemSelectedListener() {
    public void onItemSelected(AdapterView parent, View v, int position, long id) {
            feet = parent.getSelectedItemPosition()+2;
    }
    public void onNothingSelected(AdapterView parent) {
    }
};
}

你可能感兴趣的:(使用接口Adapter 下拉列表)