/** * Sets the IME options for a spinner based on its ordering. * * @param spinner The spinner. * @param spinnerCount The total spinner count. * @param spinnerIndex The index of the given spinner. */ private void setImeOptions(NumberPicker spinner, int spinnerCount, int spinnerIndex) { final int imeOptions; if (spinnerIndex < spinnerCount - 1) { imeOptions = EditorInfo.IME_ACTION_NEXT; } else { imeOptions = EditorInfo.IME_ACTION_DONE; } // check if the spinner is init ok if (spinner.getChildCount() != PICKER_CHILD_COUNT) { Log.e(TAG, "spinner.getChildCount() != 3,It isn't init ok.return"); return; } // get the middle EditText of NumberPicker TextView input = (TextView) spinner.getChildAt(1); input.setImeOptions(imeOptions); }
private void init(Context context, AttributeSet attrs, int defStyle) { // Load custom attributes final int layout; final CharSequence text; final CharSequence hint; final ColorStateList hintColor; final int inputType; final int imeOptions; if (attrs == null) { layout = R.layout.float_label; text = null; hint = null; hintColor = null; inputType = EditorInfo.TYPE_CLASS_TEXT; imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; } else { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabel, defStyle, 0); layout = a.getResourceId(R.styleable.FloatLabel_android_layout, R.layout.float_label); text = a.getText(R.styleable.FloatLabel_android_text); hint = a.getText(R.styleable.FloatLabel_android_hint); hintColor = a.getColorStateList(R.styleable.FloatLabel_android_textColorHint); inputType = a.getInt(R.styleable.FloatLabel_android_inputType, EditorInfo.TYPE_CLASS_TEXT); imeOptions = a.getInt(R.styleable.FloatLabel_android_imeOptions, EditorInfo.IME_ACTION_UNSPECIFIED); a.recycle(); } inflate(context, layout, this); mEditText = (TextView) findViewById(R.id.edit_text); if (mEditText == null) { throw new RuntimeException("Your layout must have an EditText whose ID is @id/edit_text"); } mEditText.setHint(hint); mEditText.setText(text); if (hintColor != null) { mEditText.setHintTextColor(hintColor); } mEditText.setInputType(inputType); mEditText.setImeOptions(imeOptions); mLabel = (TextView) findViewById(R.id.float_label); if (mLabel == null) { throw new RuntimeException("Your layout must have a TextView whose ID is @id/float_label"); } mLabel.setText(mEditText.getHint()); // Listen to EditText to know when it is empty or nonempty mEditText.addTextChangedListener(new EditTextWatcher()); // Check current state of EditText if (mEditText.getText().length() == 0) { mLabel.setAlpha(0); mLabelShowing = false; } else { mLabel.setVisibility(View.VISIBLE); mLabelShowing = true; } // Mark init as complete to prevent accidentally breaking the view by // adding children mInitComplete = true; }