Android 下拉框的使用方法 直接上代码
<Spinner
android:id="@+id/spinner"
android:layout_width="100px"
android:layout_height="80px">
</Spinner>
Spinner m_Spinenr = (Spinner)findViewById(R.id.spinner);
final String[] list = {"A","B","C","D","E","F","G"};
String value = "";
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.custom_spiner_text_item,list);
//参数2是样式 R.layout.custom_spiner_text_item 是自定义的样式 是在res/layout/ 目录下 一个名为 custom_spiner_text_item 文件里定义的样式 如下
/*
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textViewCustom"
style="?android:attr/spinnerItemStyle"
android:layout_width="100px"
android:layout_height="40px"
android:textSize="20sp" />
*/
//系统自带样式有三种
// simple_spinner_item simple_spinner_dropdown_item simple_expandable_list_item_1
m_Spinenr.setAdapter(adapter );
m_Spinenr.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
value = list [pos]; //取出选中的值
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});