下拉列表

public class MainActivity extends AppCompatActivity {

private Spinner s;
private String[] dataSource = new String[]{"jikexueyuan","jkxy","iwen"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    s = (Spinner)findViewById(R.id.spinner);
    s.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,dataSource));

    s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView parent, View view, int position, long id) {
            System.out.println("用户选择的是"+dataSource[position]);
        }

        @Override
        public void onNothingSelected(AdapterView parent) {

        }
    });
}

}

你可能感兴趣的:(下拉列表)