EditText 控件 android/java

private EditText depthRawChannel;
if(depthRawChannel != null){
   // depthRawChannel.clearFocus();
    depthRawChannel.addTextChangedListener(mTextWatcher);
    depthRawChannel.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId,
                                      KeyEvent event) {
            Log.d(TAG, "onEditorAction actionId="+actionId);
            //一开始只判断是回车键而没有判断  ACTION_UP以至于每次按回车都导致触发2次
            if ( (actionId == EditorInfo.IME_ACTION_DONE) ||(actionId == EditorInfo.IME_ACTION_NEXT)||
                    ((event != null && event.isShiftPressed()==false) &&
                    (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) &&
                    (event.getAction() == KeyEvent.ACTION_DOWN )) ){
                //validateSN(); //自定义操作
                //return true;  //表示本次操作完成 不再往外传播本事件
                Log.d(TAG, "onEditorAction1");
                hideSoftKeyboard(depthRawChannel,getContext());
                depthRawChannel.setCursorVisible(false);
                bottom_view.setVisibility(View.VISIBLE);
                return true;
            }
            return false;
        }
    });
}
///

private TextWatcher mTextWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        Log.d(TAG, "beforeTextChanged");
        bottom_view.setVisibility(View.INVISIBLE);
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

        String value = depthRawChannel.getText().toString();
        if ("".equalsIgnoreCase(value)){
            channelValue = 0;
        }
        if(value != null && !("".equalsIgnoreCase(value)) && (Integer.parseInt(value) <= 15) ){
            channelValue = Integer.parseInt(value);
        }
        if(value != null && !("".equalsIgnoreCase(value)) && (Integer.parseInt(value) > 15)){
            Toast.makeText(getContext(), ".....",
                    Toast.LENGTH_SHORT).show();
            channelValue = 0;
        }
        
        Log.d(TAG, "onTextChanged channelVale: "+ channelValue);
        Message msg = Message.obtain();
        msg.what = CameraOpt.MSG_SET_CHANNEL_VALUE;
        msg.arg1 = channelValue;
        mCameraOpt[1].getHandler().sendMessage(msg);
    }

    @Override
    public void afterTextChanged(Editable s) {
        Log.d(TAG, "afterTextChanged");

    }
};

/* 隐藏或显示软键盘*/
public static void hideSoftKeyboard(EditText editText, Context context) {
    if (editText != null && context != null) {
        InputMethodManager imm = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    }
}
public static void showSoftKeyboard(EditText editText, Context context) {
    if (editText != null && context != null) {
        InputMethodManager imm = (InputMethodManager) context
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, 0);
    }
}

相关code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值