当我点击我的EditText光标位置时,我试图制作到文本的末尾,我的代码如下:
tb_acrescimo.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
int position = tb_acrescimo.length();
Editable etext = tb_acrescimo.getText();
Selection.setSelection(etext, position);
}
});
但是它可以在Android API 2.3上运行,但不适用于4.1,有谁知道我应该怎么做?
我找到了解决我问题的其他解决方案,但没有回答我的问题,放弃了主题,所以我不会发布解决方案,好吗?
答案 0 :(得分:0)
试试这个:
tb_acrescimo.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) return;
int position = tb_acrescimo.length();
Editable etext = tb_acrescimo.getText();
tb_acrescimo.setSelection(etext, position);
}
});