公共類MainActivity刪除選擇項目延伸活動{
String[] DayOfWeek = { "Select Item", "1", "2", "3", "4", "5", "6" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner mySpinner = (Spinner) findViewById(R.id.spinner);
mySpinner.setAdapter(new MyCustomAdapter(MainActivity.this,
R.layout.row, DayOfWeek));
}
public class MyCustomAdapter extends ArrayAdapter<String> {
public MyCustomAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
// return super.getView(position, convertView, parent);
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.row, parent, false);
TextView label = (TextView) row.findViewById(R.id.weekofday);
label.setText(DayOfWeek[position]);
ImageView icon = (ImageView) row.findViewById(R.id.icon);
if (DayOfWeek[position] == "Sunday") {
icon.setImageResource(R.drawable.icon);
} else {
icon.setImageResource(R.drawable.icongray);
}
return row;
}
}
}
這裏是我的代碼,我能夠在旋轉顯示的價值,但我希望顯示僅在Textview中選擇項目不在Value中,同時其顯示值也告訴我如何刪除該項目,請參閱屏幕並告訴我如何刪除該項目
AFAIK這不是Android'Spinner'工作的方式:它只顯示值,而不顯示標題。所以只需使用值並刪除「選擇項目」。 – shkschneider 2014-12-05 10:40:28
正如@shkschneider所述,這不是微調器的工作原理: 在微調控制器上方添加一個textView並從微調控制器中刪除「Select item」數據 – Altoyyr 2014-12-05 10:43:19
使用spinner.setPrompt(「Select Item」);並從DayOfWeek數組中刪除這個「Select Item」字符串。 – 2014-12-05 10:44:17