2017-02-28 4 views
7

से चयनित टेक्स्ट कैसे प्राप्त करें मेरे पास ईवेंट प्रकार "typeViewTextSelectionChanged" के लिए चल रही एक एक्सेसिबिलिटी सेवा है। मैं इस घटना ट्रिगर जब भी उपयोगकर्ता किसी भी पाठ का चयन करता है को पकड़ने के लिए कर रहा हूँ, लेकिन मैं कैसे AccessibilityNodeInfo या AccessibilityEvent से चयनित पाठ सामग्री वस्तुओंAccessibilityNodeInfo

उत्तर

1

निम्नलिखित अंदर चला जाता है,

onAccessibilityEvent(AccessibilityEvent event){} 

और फिर मिलता है ,

//Get the source 
AccessibilityNodeInfo source = event.getSource(); 

//Grab the parent of the view that fired the event. 
AccessibilityNodeInfo rowNode = getListItemNodeInfo(source); 

//Using this parent, get references to child node, the selected text 
AccessibilityNodeInfo textNode = rowNode.getChild(0); 

//Get the text values 
String text = textNode.getText(); 

या

वैकल्पिक रूप से आपके मामले में, निम्नलिखित को ठीक काम करना चाहिए। चूंकि, यह एक "typeViewTextSelectionChanged" ईवेंट है, यह स्पष्ट रूप से एक संपादन टेक्स्ट से है।

String text=event.getText(); 

अधिक जानकारी के लिए, एक नज़र here और here

+0

मैं, getListItemNodeInfo के लिए किसी भी दस्तावेज़ प्राप्त नहीं कर पा रहे आप जहां कि देखा के लिए कृपया सकता है? – Jayce