I have app with edittext where user simply writes something with the softkeyboard. After user will click at the button and he will see popupwindow, in this case user still have seen keyboard. When user will click outside the popup, it should disappear, and it work ok, but if user will click at keyboard, popup won't disappear. Maybe someone has deal with same problem and can help me.
Steps:
Open app
Invoke keyboard
Invoke popupwindow
Start input
result: Popup is not hidden, text is not inputted
If I understand you correctly, you want that the keyboard to disapper when the user clicks on it?
If so, do this for your EditText:
final EditText sample = (EditText) findViewById(R.id.popupET);
sample.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(sample.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
What it does is simply wait for the user to input any key (press on the keyboard) and then it hides it.
The sample EditText is the field you currently have in your code.
Let me know if everything works
Related
I have created an app where the user can enter some text and it searches the database once the user presses the search button. I have now modified this so it works with NFC. The NFC tags stores some text (Hello World) and once the tag has been tapped on the phone the text (Hello World) is inserted into the textview. The user can then press the search button and so on.
Is it possible to automatically press the search button once text has been entered into the textbox. For Example, The user taps their phone on the NFC tag, Hello World is entered in the textbox and the search occurs automatically without the user having to press the button.
Is this possible?
Thanks
When user taps their phone on the NFC tag, enter Hello World in the textbox and programmatically click SearchButton using performClick().
button.performClick();
Yes it can be by using textwatcher on editext.
SerachEditText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if(s.toString().contains("HelloWord Or You unique NFC Text")){
//Enter here Button Pressed Code
}
}
#Override
public void afterTextChanged(Editable arg0) {
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
});
I'm creating a remote control that also let's people enter characters for a Minix android dongle. Via another app on a tablet or smartphone, people can enter data that is send to the dongle for input purposes.
I'm trying to create a keyboard programmatically when i push on a button, with which I can get the keys that are entered in on the keyboard. I also have to delete the keyboard when i click on ANYTHING ELSE then the keyboard. This is the important part, since I'm using fragments and there are other views on the screen which, when pressed, also have to remove the keyboard.
So how can i know when there is a touchinput on the phone/tablet that is not on the keyboard? I've tried the onfocusChanged, but this didn't work since my focus won't change if I press something on my screen.
Currently I'm using this code, which allows me to show a keyboard when I press a button and intercept all the text that is entered on the keyboard.
mKeyboard = (Button) view.findViewById(R.id.buttonKeyboard);
mKeyboard.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final EditText plainTextInput = (EditText) view.findViewById(R.id.PlainTextInput);
plainTextInput.requestFocus();
InputMethodManager keyboard = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(plainTextInput, 0);
plainTextInput.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.e(TAG, s.toString());
}
#Override
public void afterTextChanged(Editable s) {
}
});
plainTextInput.getLayout();
}
});
Now how can I know when the user has pressed somewhere outside the keyboard, so I can close the keyboard? Or are there other ways of adding a keyboard without invisible edittexts?
When testing an android project on an emulator the keyboard seems to work fine. However, when I test on my samsung phone the keyboard works incorrectly. One problem is that when my first display comes up the keyboard automatically appears although it doesn't in an emulator. Secondly, if I type something and hit the return or enter key, the keyboard won't disappear on my phone. Is there a separate step needed to dismiss the keyboard? Thirdly, sometimes when I hit hit the enter key, it causes the cursor to go to a new line rather than submitting the data. Again, none of this is a problem with the emulator. So what do I have to do to make the keyboard work correctly on my phone device?
Below is my code for receiving and submitting data with ana AutocompleteText view.
autoComplete = (AutoCompleteTextView) findViewById(R.id.suggest);
autoComplete.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable editable) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
String newText = s.toString();
int len = newText.length();
// Toast.makeText(getApplicationContext(), "Text changed count = " + String.valueOf(len), Toast.LENGTH_LONG).show();
if(len > 1)
new getData().execute(newText);
}
});
Sometimes when I hit the enter key, it goes to another line rather than executing my asynchronous task.
you required to forcefully open and close the soft keyboard for your requirements.
for Open soft keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(your_edit_text, InputMethodManager.SHOW_FORCED);
for Close soft keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(your_edit_text.getWindowToken(), 0);
for correct working done(Enter) key you should put following properties to Edit Text in .XML file.
android:singleLine="true"
android:imeOptions="actionDone"
I have a login page,having 2 textfields username,password and button "login" button.
when the username or password not entered alert is poping up,
when i suddenly clicks on this login button 2 alerts are poping up,
since more than click is taken.
I need to disable the button and enable during next click. What should i do?
in order to disable a button, you have to call
yourButton.setEnabled(false)
on a Button instance. To re enable it call:
yourButton.setEnabled(true)
create a method as below
boolean checkit= true;
private void showHide1() {
if (checkit) {
// first click
} else {
// second click
}
checkit= !checkit;
}
and on you button click add the method showHide1();
You can combine blackbelt's solution with mine.
Add a TextWatcher to your EditText and enable or disable the button when text is entered in the EditText.
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
charCount = Integer.valueOf(s.length());
if (charCount > 0) {
// ENABLE THE BUTTON
boolean blnButtonStatus = YOUR_BUTTON.isEnabled();
if (blnButtonStatus== false) {
YOUR_BUTTON.setEnabled(true);
}
} else if (charCount == 0) {
// DISABLE THE BUTTON
YOUR_BUTTON.setEnabled(false);
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// DO NOTHING HERE
}
#Override
public void afterTextChanged(Editable s) {
// DO NOTHING HERE
}
This way, the code will automatically disable the Button if there is nothing typed in the Password and /or Username fields. No accidental clicks.
I have a simple Activity with 3 EditText fields.
User, Pass, Confirmation
After typing something in the User field and the person clicks next on the keyboard, I have a setOnFocusChangeListener on there that will validate the input. If the validation fails a Dialog opens with a message and an OK button.
After the Dialog is closed I tried a requestFocus on my User EditText in many variations, by releasing it on Pass, by trying to release on User again, by requesting than clearing and requesting again but when I click on another field the softkeyboard won't open again or I end up with two EditText fields with the blinking cursor.
Any ideas?
I suggest validating the user's input with a TextWatcher:
EditText textbox = new EditText(context);
textbox.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {
// Your validation code goes here
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
});
Only handle validation in the afterTextChanged method, don't touch the other two, as advised in the documentation. However afterTextChanged get's fired, every time the input changes, so if the user enters the word "hello" this method get's called when h is entered, then again when e is entered and so on... Furthermore, if you modify the edittext value in afterTextChanged, the method get's called too.
An alternative is to validate the user input when the EditText loses focus. For this purpose you could use:
textbox.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// Your validation code goes here
}
});
However beware, that some widgets might not grab focus, so your Edittext never loses it (had that with Buttons for instance).
Furthermore the EditText offers a setError method, which marks the edittext with a red error mark and shows the text passed to setError to the user (the text can be set by you when calling setError("Your error message")).