我怎样才能复制的TextView节不是所有的,在这个code? [英] How can I copy Section of textView not all of that in this code?

查看:125
本文介绍了我怎样才能复制的TextView节不是所有的,在这个code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Naddy先生此code复制的TextView的API到剪贴板7

I have this code from Mr Naddy for copying textView to clipboard in API 7

TextView textView=(TextView)findViewById(R.id.textView1);
registerForContextMenu(textView);

然后重写onCreateContextMenu -

Then override onCreateContextMenu -

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    //user has long pressed your TextView
    menu.add(0, v.getId(), 0, "Copy");

    //cast the received View to TextView so that you can get its text
    TextView textView = (TextView) v;

    //place your TextView's text in clipboard
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 
    clipboard.setText(textView.getText());
}

它的工作原理.....但用户可以只复制所有的TextView的.................我想允许用户如果他愿意,他可以复制的TextView的部分....也许用户想要复制例如有些话不是所有的TextView的???????

It works ..... but the User can copy just all of textview ................. I want allow to user if he wants he can copy section of textview .... maybe user want to copy for example some words not all of textview ???????

我应该怎么办?

推荐答案

你试过吗?

TextView tv;
String stringYouExtracted = tv.getText().toString;
int startIndex = tv.getSelectionStart();
int endIndex = tv.getSelectionEnd();
stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);

在这里找到:<一href=\"http://stackoverflow.com/questions/6624763/android-copy-to-clipboard-selected-text-from-a-textview\">Android: [复制到一个TextView 剪贴板选中的文本

这篇关于我怎样才能复制的TextView节不是所有的,在这个code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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