Kewin Björk Nielsen Kewin Björk Nielsen - 4 months ago 12
Android Question

how to activite a button when the user hits enter on a specific edittext

how do i activate btn_aprove when the user hits enter/next/ready from shelfnumberbox when the user has text in it

shelfnumberbox.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(Editable editable) {

btn_aprove.performClick();
}
});

Answer

Try this :

shelfnumberbox.setOnEditorActionListener(new OnEditorActionListener() {        
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if(actionId==EditorInfo.IME_ACTION_DONE){
            btn_aprove.performClick();
        }
    return false;
    }
});