2012-07-10 12 views
6

क्यों TextView हाइपरलिंक काम नहीं कर रहा है।टेक्स्ट व्यू हाइपरलिंक काम नहीं कर रहा है?

कस्टम dialog box के अंदर हाइपरलिंक का उपयोग करना।

हाइपरलिंक प्रकट नहीं होता है।

जहां मैं गलत हूं। इसे कैसे हल करें। मुझे मार्गदर्शन दो।

XML कोड

<TextView 
android:id="@+id/google_Link" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:gravity="center" 
android:padding="10dip" 
android:textSize="20dip" 
android:linksClickable="true" 
android:autoLink="all" 
android:textColorLink="#306EFF" 
android:text="" /> 

एंड्रॉयड कोड

TextView googleLink = (TextView) layout.findViewById(R.id.google_Link); 
googleLink.setClickable(true); 
googleLink.setMovementMethod(LinkMovementMethod.getInstance()); 
googleLink.setText(Html.fromHtml("<a href=`http://www.google.co.in`>Google</a>")); 

एंड्रॉयड प्रकट कोड पहले से

<action android:name="android.intent.action.VIEW" /> 
<category android:name="android.intent.category.DEFAULT" /> 
<category android:name="android.intent.category.BROWSABLE" /> 

धन्यवाद है है।

+0

बैकटिक स्ट्रिंग सीमांकक के लिए HTML में इस्तेमाल नहीं कर रहे हैं। उद्धृत स्ट्रिंग के अंदर उद्धरण चिह्नों को एम्बेड करने के लिए जावा में '\" 'का प्रयोग करें। मैं 'setClickable()' और 'setMovementMethod()' से भी छुटकारा पाउंगा, क्योंकि उन्हें आपके प्रस्तावित 'टेक्स्ट व्यू' सामग्री द्वारा संभाला जाना चाहिए। – CommonsWare

उत्तर

5

केवल इस लिंक बदलें, यह काम करेगा:

 TextView textView=(TextView) findViewById(R.id.link); 
     textView.setClickable(true); 
     String linkTxt=getResources().getString(R.string.link); 
     textView.setMovementMethod(LinkMovementMethod.getInstance()); 
     textView.setText(Html.fromHtml(linkTxt)); 

strings.xml में इस जोड़ें:

<string name="link">&lt;a href=http://www.google.co.in&gt;Google&lt;/a&gt;</string> 
+0

धन्यवाद। यह काम कर रहा है। लेकिन कैसे जोड़ना है मेरा कस्टम शीर्षक Google। – Sekar

+0

धन्यवाद आकाश। यह काम कर रहा है। – Sekar

+0

यह काम नहीं कर रहा है – JosephM

0

यह काम नहीं कर रहा है क्योंकि आप TextView पर href सेट नहीं कर सकते हैं।

आप एक OnClickListener जो उस में इस onClick विधि है है सेट करना होगा:

String url = "http://www.google.co.in"; 
Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.parse(url)); 
startActivity(i); 

उसके बाद आप इस तरह अपने TextView को श्रोता सेट कर सकते हैं: googleLink.setOnClickListener(myListener);

फिर अनुप्रयोग चलाने और क्लिक सही ढंग से संभाला जाना चाहिए।

+0

धन्यवाद। यह काम कर रहा है। लेकिन हाइपरलिंक दिखाई नहीं दे रहा है। हाइपरलिंक कैसे सेट करें। – Sekar

+0

आप इसके लिए 'टेक्स्ट व्यू' की 'सेटटेक्स्ट ("http://www.google.co.in") विधि का उपयोग कर सकते हैं। – keyboardsurfer

+0

धन्यवाद। काम कर रहा है। लेकिन जब मैं 'सेटटेक्स्ट ("Google") का उपयोग कर सकता हूं; उस समय' टेक्स्ट व्यू 'की विधि हाइपरलिंक दिखाई नहीं दे रही है। – Sekar

संबंधित मुद्दे