Code example for EditText

Methods: addTextChangedListenersetImeOptionssetInputTypesetText

0
 
		lbl = new TextView(context);
		lbl.setText("Field: ");
		addView(lbl, new LinearLayout.LayoutParams(WIDTH, LayoutParams.WRAP_CONTENT, 1));
 
		edit = new EditText(context);
		edit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
		edit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
 
		addView(edit,  new LinearLayout.LayoutParams(WIDTH, LayoutParams.WRAP_CONTENT, 1));
		// Update the value when the edit box changes 
		edit.addTextChangedListener(new TextWatcher() {
 
			@Override 
			public void afterTextChanged(Editable s) {
				value = Double.parseDouble(s.toString());
				if (changeListener != null && localUpdate == false)
					changeListener.run();
			} 
 
			@Override 
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			} 
 
			@Override 
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			} 
		}); 
 
		setPadding(5,5,5,5);
 
		setMinimumWidth(300);
		setValue(0); 
	} 
 
	//! This is the constructor used by the code 
	public NumericalFieldView(Context context, AttributeSet attrs, UAVObjectField field, int idx) {
		this(context, attrs);
 
		// Set the label name 
		String name = field.getName();
		List<String> elements = field.getElementNames();
		if (elements != null && elements.size() > 1) {
			name = name + "-" + elements.get(idx);
		} 
		lbl.setText(name);
	} 
 
 
	@Override 
	public double getValue() { 
		return value;
	} 
 
	//! Set the input type for the editable field 
	public void setInputType(int type) {
		edit.setInputType(type);
	} 
 
	@Override 
	public void setValue(double val) {
		localUpdate = true;
		value = val;
		edit.setText(Double.toString(value));
		localUpdate = false;
	} 
 
	@Override 
	public void setOnChangedListener(Runnable run) {