昨天用到了Spinner今天把它贴出来,以备后用:
1.首先,建一个String类型的数组
String m[]={"11","qq","aa","xx","xxx","xxx"};
2.再建一个adapter : 可以是ArrayAdapter
ArrayAdapter<String> adapter
3.写入自定义的条目或系统自带的
4.setAdapter——写条目的选择监听事件
上代码———————————————————-
private Spinner spinner_select;
private ArrayAdapter<String> adapter;
private static final String m[] = {"100万", "50万", "20万", "10万", "5万"};
//spinner
adapter = new ArrayAdapter<String>(context, R.layout.spinner_layout_item, m);
spinner_select.setAdapter(adapter);
spinner_select.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//截取字段换算成10000(万)(这个不重要,自己项目用到的)
String i = m[position].substring(0,m[position].length()-1)+"0000";
mData.setThrParBiliIsrAmt(Double.parseDouble(i));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
上Item———————————————————-
水平太次,用的系统的,随便在系统的条目上更改了下布局,可用
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:textSize="@dimen/dim40"---------------------------------这里写了才有用
android:textColor="@color/C959595"
android:background="@color/white"
android:ellipsize="marquee"/>
上xml———————————————————-
<Spinner
android:id="@+id/spinner_select"
android:layout_width="@dimen/dim450"
android:layout_height="wrap_content"
android:textColor="@color/C959595"
android:textSize="@dimen/dim40"---------------这地方写了毛用没有
>
</Spinner>
“`