Android Use Done button on Keyboard to click button

后端 未结 13 1298
-上瘾入骨i
-上瘾入骨i 2020-12-02 06:30

Ok in my app I have a field for the user to input a number. I have the field set to only accept numbers. When the user clicks on the field it brings up the keyboard. On the

13条回答
  •  隐瞒了意图╮
    2020-12-02 07:10

    You can implement on key listener:

    public class ProbabilityActivity extends Activity implements OnClickListener, View.OnKeyListener {
    

    In onCreate:

    max.setOnKeyListener(this);
    

    ...

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event){
        if(keyCode == event.KEYCODE_ENTER){
            //call your button method here
        }
        return true;
    }
    

提交回复
热议问题