I want to select some text inside an EditText which is the child element of a ListView. The selected text has to be set on a clipboard. I am unable to find any examples regarding this. How should i go about this? selectionStart and selectionEnd don't work on this. Thanks.
Asked
Active
Viewed 2,173 times
6
-
sorry, don't have much time to write required for your issue, Few minutes of SO search gave me this link, this may help you. If you already tried this I am sorry.http://stackoverflow.com/questions/2679948/focusable-edittext-inside-listview – kosa Dec 31 '11 at 22:11
-
1I have explicity said in comment don't have time. Dont be too much dictating. Here issue is yours and community is trying to help you. Dont think community will write everythin for you. If link is not useful you may ignore. Your every response is dictating and that is not good. – kosa Jan 04 '12 at 13:36
-
Hey, I am not dictating anything. I am trying to prevent the community from junk answers. Don't get me wrong! – Sultan Saadat Jan 04 '12 at 14:33
5 Answers
2
here is the possible solution . in getView method of listview perform following operation:
enter code here:
public View getView(final int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.main, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.subText = (TextView) convertView.findViewById(R.id.subTxt);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
//TEXT BOX position is 0 then
if(position == 0) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(txtEdit.getText().toString());
}
return convertView;
}
1
Use this code on list selection event
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(txtEdit.getText().toString());

loks
- 490
- 3
- 10
-
you can try this, It won't work. I have tried every possible way out there. But it doesn't seem to work. There is an issue with list focus in android. It always confuses between child elements and parent elements. – Sultan Saadat Dec 28 '11 at 06:46
0
EditText already provide this functions on long press....means pressing a long touch on editText it pops up with context menu asking select all, select text, copy all.

Kri
- 1,846
- 2
- 13
- 17
-
Please try doing that in a listview and then we can discuss it later on. – Sultan Saadat Dec 27 '11 at 06:58
-
sorry, it was my mistake that haven't saw the same thing in ListView. Now i also wonder how to do that. – Kri Dec 27 '11 at 18:36
0
You can open one dialog on editText long click event inlistView custom adapter and display two option copy and paste in them
you can copy text programically using
ClipboardManager clipboard =
(ClipboardManager) c1.getSystemService(c1.CLIPBOARD_SERVICE);
clipboard.setText("Text to copy");
and get Text Using
System.out.println(clipboard.getText());

bindal
- 1,940
- 1
- 20
- 29
-
don't you understand the problem. Listview has issues with child elements. – Sultan Saadat Dec 28 '11 at 14:29
0
InputConnection ic = getCurrentInputConnection();
ExtractedText extracted = ic.getExtractedText(
new ExtractedTextRequest(), 0);
/*If selection start and end are not equal then selected text
* needs to be deleted and updated to core*/
if (extracted!= null && extracted.selectionStart != extracted.selectionEnd) {
}
Use api given by ExtractedText