EDITTEXT行号和currentline光标位置。 [英] Edittext line number and currentline cursor position.

查看:246
本文介绍了EDITTEXT行号和currentline光标位置。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我工作的一个Android应用程序。我创建了功能的自定义键盘。我使用的是EditText上显示所输入的文本。编辑文本可能有lines.Now我的问题N多的是我有一个向上按钮,在我的keyboard.So如果我点击了按钮,那么我必须去的previous线相同position.But我能不能找出currentline的EditText上线人数和光标的位置。请帮我的朋友

Now I am working on a Android application. I created a custom keyboard with functionalities. I am using a edittext for displaying the entered texts. Edit text may have n number of lines.Now my problem is I have a up button in my keyboard.So if I click the up button then i have to go the previous lines same position.But I couldn't able to find out the edittext line number and curser position of the currentline. Please help me friends

推荐答案

当前光标所在行试试这个:

public int getCurrentCursorLine(EditText editText)
{    
    int selectionStart = Selection.getSelectionStart(editText.getText());
    Layout layout = editText.getLayout();

    if (!(selectionStart == -1)) {
        return layout.getLineForOffset(selectionStart);
    }

    return -1;
}

和光标的位置,用 getSelectionStart()

int cursorPosition = myEditText.getSelectionStart();

这篇关于EDITTEXT行号和currentline光标位置。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆