我有一个的ListView
,其中每个项目是的TextView
。
I have a ListView
where each item is a TextView
.
我想启用类似于长preSS行为的EditText
,随着像全选,全部剪切项显示默认的上下文菜单, 全部复制,等等。
I want to enable the long press behaviour similar to an EditText
that displays the default context menu with items like "Select all", "Cut all", "Copy all", etc.
有一种简单的方法,使本作的TextView
?
Is there an easy way to enable this for a TextView
?
我觉得我有一个解决方案。
只需致电
registerForContextMenu(yourTextView);
I think I have a solution.
Just call
registerForContextMenu(yourTextView);
和您的的TextView
将被注册为接收上下文菜单事件。
and your TextView
will be registered for receiving context menu events.
然后重写 onCreateContextMenu
在活动
:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
//user has long pressed your TextView
menu.add(0, v.getId(), 0, "text that you want to show in the context menu - I use simply Copy");
//cast the received View to TextView so that you can get its text
TextView yourTextView = (TextView) v;
//place your TextView's text in clipboard
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(yourTextView.getText());
}
希望这有助于你和其他人寻找一种方式来复制从文本的TextView
上一篇:如何使用Intent.ACTION_APP_ERROR作为一个&QUOT的手段;反馈"框架的Android?作为一个、如何使用、框架、手段
下一篇:在web视图Android上使用navigator.geolocation.getCurrentPosition 2.0+(PhoneGap的相关)视图、navigator、Android、web