在EditText中移动光标:我创建了一个可以向上,向下,向左,向右移动光标的按钮。我不知道要上下调整

时间:2017-04-23 15:52:17

标签: java android button android-edittext cursor

 public void onClick (View v){
            if (v.getId() == R.id.btnUp) {
            }
            if (v.getId() == R.id.btnDown) {
                int start = txtInput.getSelectionStart();
                int haha = start / 2;
                int hehe = haha / 2;
                int samp = haha + hehe;
                Log.e("up", samp + "");
                if (start >= 1 && samp >= 1) {
                    txtInput.setSelection(samp);
                    Log.e("up", samp + "");
                }
            }
            if (v.getId() == R.id.btnLeft) {
                int start = txtInput.getSelectionStart();
                if (start >= 1) {
                    txtInput.setSelection(start - 1);
                    Log.e("left", start + "");
                }
            }
            if (v.getId() == R.id.btnRight) {
                int start = txtInput.getSelectionStart();
                if (start < txtInput.length()) {
                    txtInput.setSelection(start + 1);
                    Log.e("right", start + "");
                }
            }
        }

0 个答案:

没有答案