Java Code Examples for android.widget.TextView#getSelectionStart()

The following examples show how to use android.widget.TextView#getSelectionStart() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: android   File: LogsActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onPostExecute(String s) {
    TextView content = findViewById(R.id.log_content);
    if (content.getSelectionStart() == content.getSelectionEnd()) {
        content.setText(s);
    }
    super.onPostExecute(s);
}
 
Example 2
Source Project: timecat   File: CopyActivity.java    License: Apache License 2.0 5 votes vote down vote up
private String getSelectedTextViewText(TextView textView) {
    if (textView == null) {
        return getSelectedText();
    } else {
        CharSequence text = textView.getText();
        if (textView.getSelectionStart() == textView.getSelectionEnd()) {
            return text.toString();
        } else {
            CharSequence selected = text.subSequence(textView.getSelectionStart(), textView.getSelectionEnd());
            return selected != null ? selected.toString() : text.toString();
        }
    }
}
 
Example 3
public static String getSelection(TextView tv) {
	final int e=tv.getSelectionEnd();
	final int s=tv.getSelectionStart();
	if (e < 0 || s < 0 || s == e) {
		return tv.getText().toString();
	}
	return tv.getText().toString().substring(s, e);
}