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) {
}
});
Related
I used EditText instead of SearchView. But here the problem is different I used to search in ListView and data in the ListView is coming when I hit the search api..let me explain..
Actually I have an api the when I put char in EditText , I get that char from EditText and hit the api in postman by passing the parameters in body, two params I have passed("key"=the char i get from EditText, user_id=null).
And I want to search the data like when I press "m" then "m" will post as value of "key" and shows the data , at the same time if i press "mo" then the api again hits at the same time and get me the results in ListView
Please help me...
mSearchFriends.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
String input;
if(actionId == EditorInfo.IME_ACTION_DONE)
{
input = String.valueOf(mSearchFriends.getText());
new PostSearchApi(Add.this) {
#Override
public void fetchData(String output) {
Log.d("response>>>>>",output);
//input = String.valueOf(mSearchFriends.getText());
rowItemListForSearchList = new ArrayList<>();
mSearchListAdapter = new SearchListAdapter(getApplicationContext(),rowItemListForSearchList);
getjsonOfContact(output);
lvContacts.setAdapter(mSearchListAdapter);
mSearchListAdapter.notifyDataSetChanged();
mTextView_No_Result_Found.setVisibility(View.GONE);
}
}.execute(input,"");
It shows me result but after pressing the the arrow button on phone keyboard. What I want is I want to search random data when I type a character. I also tried the code in OnTextChanged method but when I type "a" then api hits and takes time when it completed then only i can type other character..
But the necessity is the functionality like finding the friends on facebook
Since no code provided by you, as far as I understand your ques, you can get realtime text changing events from EditText like this:
yourEditText.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) {
//on Text change event. s is the text that is entered
// put your code here. Make a hit to your api and pass `s` as your parameter.
}
#Override
public void afterTextChanged(Editable s) {
}
});
I am working on an Android app and I am trying to implement a feature that I have found online. I am tying to do is when user clicks on edit text, for example, if user clicks on "Username" edit text, the setOnFocusChangeListener will check things and will start animation for label to fadeIn and fadeOut, here my codes
userSignupPasswordET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (userSignupPasswordET.hasFocus()) {
signupPassWDTV.startAnimation(fadeIn);
} else {
if (userSignupPasswordET.getText().toString().length() == 0) {
signupPassWDTV.startAnimation(fadeOut);
}
}
}
});
The feature I am trying to do is here, on youtube. But the problem I am facing is that I have three fields, username, password and email. So if I click on username it is working and fadIn animation for username label works and also if I do not enter anything fadeOut animation works when I move to other edit text and the other edit text's own setOnFocusChangeListener works. But problem is the if I don't enter anything in any of them just keep switching them, keep changing their focus, the other two edit text's setOnFocusChangeListener gets triggered and starts fadeIn animation and than fadeOut animation. So I don't know what to do. Any suggestion? Remember, if I don't enter anything in edit field and just keep changing/toggling them, this problem is getting triggered. If I enter something in one, it changes and label stays visible.
You can add your logic on TextChangedListener()
edittext.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
#Override
public void afterTextChanged(Editable et) {
}
});
so that your animation get called only when you enter something on your edittext
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?
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
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")).