2012-06-14 10 views
5

में इलिप्सिज्ड टेक्स्ट कैसे प्राप्त करें I एंड्रॉइड द्वारा एक इलिप्सिस में छोटा टेक्स्ट कैसे प्राप्त किया जा सकता है?टेक्स्टव्यू

<TextView 
    android:layout_width="120dp" 
    android:layout_height="wrap_content" 
    android:ellipsize="end" 
    android:singleLine="true" 
    android:text="Um longo texto aqui de exemplo" /> 

एक डिवाइस पर इस TextView इस तरह दिखाया गया है::

"Um longo texto a..."

मैं पाठ के बाकी कैसे मिलता है

मैं एक TextView है?

मैं getRestOfTruncate() जैसे कुछ ढूंढ रहा हूं जो "qui de exemplo" लौटाएगा। ।

+0

मैं अपने प्रश्न के शीर्षक और पाठ तय की। काश मैं तुम्हारे लिए जवाब था, लेकिन मुझे नहीं लगता कि ऐसा करने का एक तरीका है। यहां उपयोग का मामला क्या है? –

+0

धन्यवाद @AustynMahoney, शायद इसे बनाने के लिए कुछ किया जाना चाहिए, अन्यथा, मैं कुछ बनाउंगा, समस्या यह है कि यह और अधिक कठिन होगा, लेकिन अगर मैं यहां पोस्ट करता हूं – ademar111190

+1

'android: text =" @ string/full_text का उपयोग करें "xml लेआउट में, और 'जब भी आपको इसकी आवश्यकता हो, जावा कोड में' getString (R.string.full_text) '। – yorkw

उत्तर

5
String text = (String) textView.getText().subSequence(textView.getLayout().getEllipsisStart(0), textView.getText().length()); 
+0

सही काम करता है लेकिन मुझे एक पोस्ट के अंदर अपना कोड डालने की आवश्यकता है क्योंकि पहले टेक्स्टव्यू को डिज़ाइन किया जाना चाहिए, फिनिश में मैं इसे बना देता हूं: नया हैंडलर()। पोस्टडेलेड (आपके कोड के साथ चलने योग्य, 1 मिलीसेगुंडो); – ademar111190

+2

यह केवल तभी काम करता है जब मेरे पास 'android: singleLine =" true "'। अगर मैं इसे 'झूठा' पर सेट करता हूं और 'एंड्रॉइड सेट करता हूं: maxLines'' के अलावा कुछ अन्य नंबर पर, तो यह विधि हमेशा पूरे पाठ को वापस लौटाती है जैसे कि यह बिल्कुल लंबित नहीं था। –

0

textView.getLayout का उपयोग करना() getEllipsisStart (0) तभी काम करता है एंड्रॉयड: Maxlines सेट है::

public static String getEllipsisText(TextView textView) { 
    // test that we have a textview and it has text 
    if (textView==null || TextUtils.isEmpty(textView.getText())) return null; 
    Layout l = textView.getLayout(); 
    if (l!=null) { 
     // find the last visible position 
     int end = l.getLineEnd(textView.getMaxLines()-1); 
     // get only the text after that position 
     return textView.getText().toString().substring(end); 
    } 

    return null; 
} 
singleLine = "true"

यहाँ एक समाधान है कि एंड्रॉयड अगर काम करेगा

याद रखें: दृश्य के बाद यह कार्य पहले से दिखाई दे रहा है।

उपयोग:

textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      textView.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
      Log.i("test" ,"EllipsisText="+getEllipsisText(textView)); 
     } 
    }); 
संबंधित मुद्दे