Code example for EditText

Methods: getText, getWindowToken, setVisibility

0
 
		editValue = (EditText)customView.findViewById(R.id.editValue);
		editValue.setOnKeyListener(new View.OnKeyListener() {
			@Override 
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				String val = editValue.getText().toString();
				if(val.length() > 0) {
					value = Integer.parseInt(val);
					if(value < min) {
						value = min;
					}else if(value > max) {
						value = max;
					} 
					resetValues(); 
				} 
				if(keyCode == KeyEvent.KEYCODE_ENTER) {
					closeEditText(); 
				} 
				return false; 
			} 
		}); 
		 
		// set onclick to text (show soft keyboard) 
		textValue = (TextView)customView.findViewById(R.id.textValue);
		textValue.setOnClickListener(new View.OnClickListener() {
			@Override 
			public void onClick(View v) { // open EditText
				editValue.setText(String.valueOf(value));
				editValue.setVisibility(View.VISIBLE);
				textValue.setVisibility(View.GONE);
				editValue.requestFocus();
				 
				inputMethodManager.showSoftInput(editValue, InputMethodManager.SHOW_FORCED);
			} 
		}); 
 
		// set on click to '-' button 
		customView.findViewById(R.id.valueMin).setOnClickListener(this);
		 
		// set on click to '+' button 
		customView.findViewById(R.id.valuePlus).setOnClickListener(this);
 
		resetValues(); 
	} 
	 
	@Override 
	public void onClick(View v) {
		if(v.getId() == R.id.valueMin) {
			value -= step;
		}else { 
			value += step;
		} 
		editValue.setText(String.valueOf(value));
		resetValues(); 
	} 
	 
	private void closeEditText() { 
		inputMethodManager.hideSoftInputFromWindow(editValue.getWindowToken(), 0);
		editValue.setVisibility(View.GONE);
		textValue.setVisibility(View.VISIBLE);
	} 
	 
	private void resetValues() { 
		int seekbarValue = (value - min) / step;