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.
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 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?
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 8 edit texts each allow only one character.when user enter something it automatically moves to next edit text. It's work fine by using onTextchanged.But i need to move backward also like when user enter back button it automatically moves to previous edit text and when enter something it move again next edit text. How i can do it.Please can any one help.
Any help would be highly appreciated.
editText_Pin1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start,int before, int count) {
if(editText_Pin1.getText().toString().length()==1) { //size as per your requirement {
editText_Pin2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,int count, int after) {
}
#Override
public void afterTextChanged(Editable arg0) {
}
});
Try something like this...
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
if(editText_Pin2.getText().toString().length()==1){//Here you will check the last editField which has lenght == 1
editText_Pin1.requestFocus();
return false;//This will make sure your activity doesn't gets finished
}
}
return super.onKeyDown(keyCode, event);
}
Hope this helps..
you can do it by oveeriding the onBackPressed method
#Override
public void onBackPressed() {
//check here which edittext has current focus,change the focus to previous edittext
//you can use edittext array also.And also check if it is the first edittext then do nothing
return;
}
You have several options:
Activity.onBackPressed()
Activity.onKeyDown() or Activity.onKeyUp()
View.setOnKeyListener() on each of your EditTexts
View.onKeyPreIme()
I'd probably go with #1 or #3