如何获得从选定文本的EditText android系统中? [英] How to get selected text from edittext in android?

查看:144
本文介绍了如何获得从选定文本的EditText android系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文字被选择的EditText。我想从EditText上的点击按钮的选定文本。

请建议我使用的链接或样品code。

解决方案

 的EditText等=(EditText上)findViewById(R.id.edit);

INT startSelection = et.getSelectionStart();
INT endSelection = et.getSelectionEnd();

字符串selectedText = et.getText()的toString()子(startSelection,endSelection)。
 

I have a edittext in which some text are selected . I want to get only selected text from edittext on click of button .

Please suggest me usable link or sample code.

解决方案

EditText et=(EditText)findViewById(R.id.edit);

int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();

String selectedText = et.getText().toString().substring(startSelection, endSelection);

这篇关于如何获得从选定文本的EditText android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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