Code example for EditText

Methods: selectAlladdTextChangedListenersetSingleLinesetTextsetTextAppearancesetTextColorsetTransformationMethod, setOnFocusChangeListener

0
				final TextBox box = TextBox.from(pointer);
				if(box == null)
					return; 
				 
				// create text view 
				final EditText et = new EditText(context);
				et.setSingleLine(true);
				et.setTextAppearance(context, android.R.style.TextAppearance_Medium);
				et.setTextColor(0xff000000);
				et.setText(box.getText());
				et.selectAll();
				if(box.isPassword())
					et.setTransformationMethod(PasswordTransformationMethod.getInstance());
				et.addTextChangedListener(new TextWatcher() {
					@Override 
					public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
						box.onTextChanged(et.getText().toString().trim());
					} 
					 
					@Override 
					public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
							int arg3) {
					} 
					 
					@Override 
					public void afterTextChanged(Editable arg0) {
					} 
				}); 
				 
				// build dialog and show 
				AlertDialog.Builder builder = new AlertDialog.Builder(context);
				 
				// view content 
				builder.setView(et);
				 
				// positive button 
				String btn = box.getPositiveButton();
				if(btn == null)
					btn = "OK";
				builder.setPositiveButton(btn, new DialogInterface.OnClickListener() {
						@Override 
						public void onClick(DialogInterface arg0, int arg1) {
							box.onOKButtonClicked(et.getText().toString().trim());
						} 
					}); 
					 
				// negative button 
				btn = box.getNegativeButton();
				if(btn == null)
					btn = "Cancel";
				builder.setNegativeButton(btn, new DialogInterface.OnClickListener() {
					@Override 
					public void onClick(DialogInterface arg0, int arg1) {
						box.onCancelButtonClicked();
					} 
				}); 
				 
				// set cancel listener 
				builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
					@Override 
					public void onCancel(DialogInterface arg0) {
						box.onCancelButtonClicked();
					} 
				}); 
				 
				// title 
				String title = box.getTitle();
				if(!TextUtils.isEmpty(title))
					builder.setTitle(title);
				 
				// message 
				String msg = box.getMessage();
				if(!TextUtils.isEmpty(msg))
					builder.setMessage(msg);
				 
				// create and show 
				// install a focus listener to make soft keyboard visible 
				final Dialog d = builder.create();
				et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
					@Override 
					public void onFocusChange(View v, boolean hasFocus) {
						if(hasFocus)
							d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
					}