android-edittext

How to calculate EditText value in Android?

北城余情 提交于 2019-12-04 19:16:30
In an Android app, I'm using two EditText controls and multiplying their two values. If one EditText is null and in the second one I put a value, it's not working properly. How can I deal with this case, in which I have a value in one EditText and a null in the other and I want to multiply the two values? First of all, you need to have a trigger for when to perform the calculation. Say it's a button, or, even better, every time the value of one of your EditText s changes: private EditText editText1, editText2; private TextView resultsText; ............................... // Obtains references

EditText - How to separate characters that are typed in a EditText in groups or blocks

你。 提交于 2019-12-04 19:13:58
Is there a way I can group characters from a EditText in blocks while the user is typing? Exemple: 1234 4567 7890 and so on? I have an edit text that support numeric numbers and has 16 char length and I would like to group them in separated blocks for a better visibility. import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.widget.EditText; public class MainActivity extends AppCompatActivity { EditText mEditText; @Override protected void onCreate(Bundle

How to add TextView and EditText using default AlertDialog programmatically

做~自己de王妃 提交于 2019-12-04 18:55:24
问题 I've been trying to add two elements in a default AlertDialog but I can't seem to make it work. Here's my code: // START Dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); TextView tv = new TextView(this); tv.setText(title); tv.setPadding(40, 40, 40, 40); tv.setGravity(Gravity.CENTER); tv.setTextSize(20); EditText et = new EditText(this); etStr = et.getText().toString(); alertDialogBuilder.setView(et); alertDialogBuilder.setTitle(title); alertDialogBuilder

Handle enter key in EditText across different devices

≯℡__Kan透↙ 提交于 2019-12-04 18:43:51
问题 Right now I'm handling the enter key in my EditText fields using a an onEditorActionListener and looking at the Action ID for IME_NULL. It works fine for all my users except one. She has an Xperia Arc. TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){ public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if(actionId == EditorInfo.IME_NULL){ if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etUser))){ ((EditText)

How can i have EditText with Clickable Spannables and still selectable by longClick?

亡梦爱人 提交于 2019-12-04 18:42:14
问题 I have TextView with spans of type ClickableStringSpan defined as below: public class ClickableStringSpan extends ClickableSpan { private View.OnClickListener mListener; int color; public ClickableStringSpan(View.OnClickListener listener,int color) { mListener = listener; this.color = color; } @Override public void onClick(View v) { mListener.onClick(v); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); ds.setColor(color); } } I set

Continuously delete contents of EditText on button hold Android [duplicate]

断了今生、忘了曾经 提交于 2019-12-04 18:21:03
This question already has an answer here : Send backspace key event to edit text (1 answer) Closed 5 years ago . How do I delete one by one the current text of edit text when I press a button and continuously delete the text one by one when I hold the press of button. Similar to what a backspace button does. Sending a backspace event won't work on my needs because it will only work if the keyboard is active. Im not using any keyboards. You have to use the Timer for this.It continuously checks the button state pressed or not. Like: private Timer _timer; final Button _button = (Button)

EditText and TabHost do not like each other

北战南征 提交于 2019-12-04 18:07:42
问题 I have a layout with EditText and TabHost containing 2 tabs. Android 1.6. I use hardware keyboard in following case. Steps to reproduce: When activity is displayed the EditText gains focus. As soon as I press any key the EditText loses focus and first tab gains it. I click on the EditText again and start typing. It works unless I press any numeric button. The first tab gains the focus again. I scroll back to the EditText with track ball. I can type anything now. Using track ball left/right on

Catching key pressed with the virtual keyboard in Android?

假装没事ソ 提交于 2019-12-04 17:54:41
问题 With the physical keyboard you can catch key presses with a KeyListener, something like: myEditText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { /* do something */ } } }); Does anyone know how to do this (or similar) with the virtual keyboard? 回答1: So far i haven't found any listener for the virtual keypad in android. I found an alternate solution i.e. i used the TextChanged event to

Block physical keyboard input in EditText

只谈情不闲聊 提交于 2019-12-04 17:54:23
I have a EditText that should not allow the user to input anything through the keyboard (soft or hard). This EditText should only allow the user to input something through keys(buttons) displayed in the screen by the app. I have disabled the soft keyboard, but I can't find a way to disable the hardware keyboard input. This input via hardware keyboard can be done using a emulator that is configured to allow input through the hardware keyboard. So, my question is, How can I block the input via physical keyboard in a EditText? Thank you! Finally got it! Code: editText.setOnKeyListener(new View

How to automatically show soft keyboard on start?

元气小坏坏 提交于 2019-12-04 17:54:13
I have an activity that only has a EditText. I want the soft keyboard to show up automatically. How can I do this? You can use this onResume: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(((EditText) findViewById(R.id.your_view)),InputMethodManager.SHOW_FORCED); I suggest that you check if there is a Hardware keyboard before you force the keyboard to appear. To hide: ((InputMethodManager) YourActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.YOUR_VIEW).getWindowToken(), 0);