设置默认选中:
public static int ugid = 1;
public void setSpinnerItemSelectedByValue(Spinner spinner,String value){
SpinnerAdapter apsAdapter= spinner.getAdapter();
int k= apsAdapter.getCount();
for(int i=0;i<k;i++){
if(value.equals(apsAdapter.getItem(i).toString())){
// spinner.setSelection(i,true);// 默认选中项
spinner.setSelection(i);// 默认选中项
break;
}
}
}
setSpinnerItemSelectedByValue(groupScene, ugid + "");
获取选中值:
String f = groupScene.getSelectedItem().toString();
xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"