android spinner控件自定义选择图层

final Spinner timeGroup = (Spinner) findViewById(R.id.timer);
		// 倒计时自定义的选择视图
		BaseAdapter baseAdapter = new BaseAdapter() {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				LinearLayout ll = new LinearLayout(GameSettingActivity.this);
				ll.setOrientation(LinearLayout.HORIZONTAL);
				ll.setGravity(Gravity.CENTER);
				TextView timeView = new TextView(GameSettingActivity.this);
				TextView unitView = new TextView(GameSettingActivity.this);
				if (position == 0) {
					timeView.setText("" + times[position]);
					timeView.setVisibility(View.GONE);
					unitView.setText("不计时");
				} else {
					timeView.setText("" + times[position]);
					unitView.setText(" " + unit);
				}

				ll.addView(timeView);
				ll.addView(unitView);
				return ll;
			}

			@Override
			public long getItemId(int position) {
				return 0;
			}

			@Override
			public Object getItem(int position) {
				return null;
			}

			@Override
			public int getCount() {
				return 5;
			}
		};

		timeGroup.setAdapter(baseAdapter);

你可能感兴趣的:(android)