Click here to Skip to main content
15,888,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void addKeyListener() {

    // get edittext component
    edittext = (EditText) findViewById(R.id.editText);
    edittext1 = (EditText) findViewById(R.id.editText1);



    // add a keylistener to keep track user input
    edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) {

        // if keydown and "enter" is pressed
            if(keyCode == EditorInfo.IME_ACTION_GO)
        {
            edittext1.requestFocus();
            return true;
        }


        return false;
     } });

     edittext1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
             @Override
             public boolean onEditorAction(TextView a, int b, KeyEvent c) {

        // if keydown and "enter" is pressed
             if(b == EditorInfo.IME_ACTION_GO) {

            //hide the keyboard
             InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
             imm.hideSoftInputFromWindow(edittext1.getWindowToken(), 0);
        // display a floating message
            Toast.makeText(MyAndroidAppActivity.this, edittext.getText().toString() + " " + edittext1.getText().toString(), Toast.LENGTH_SHORT).show();
            return true;
        }

        return false;
      } });

 }

Can you tell me how to use text watcher and should work in android 4.4. Please help me

Please rewrite the complete code and tell me
Posted
Updated 4-Jan-14 3:39am
v2
Comments
archies_gall 5-Jan-14 1:04am    
check this:

public void addKeyListener() {

// get edittext component
edittext = (EditText) findViewById(R.id.editText);
edittext1 = (EditText) findViewById(R.id.editText1);



// add a keylistener to keep track user input
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) {

// if keydown and "enter" is pressed
if(keyCode == EditorInfo.IME_ACTION_GO)
{
edittext1.requestFocus();
return true;
}


return false;
} });

edittext1.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
// if keydown and "enter" is pressed
if(b == EditorInfo.IME_ACTION_GO) {

//hide the keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
imm.hideSoftInputFromWindow(edittext1.getWindowToken(), 0);
// display a floating message
Toast.makeText(MyAndroidAppActivity.this, edittext.getText().toString() + " " + edittext1.getText().toString(), Toast.LENGTH_SHORT).show();
return true;
}

return false;
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub

}
});
}

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900