मेरे ग्राफिक लेआउट में, मेरे पास बहुत सारे टेक्स्ट हैं, जिसके अंत में एक हाइपरलिंक है। चूंकि टेक्स्ट मेरे लेआउट में पूरी तरह फिट नहीं है, इसलिए मैंने एक स्क्रॉलव्यू जोड़ा है। अब जब मैं अपना एमुलेटर शुरू करता हूं, तो केवल एक चीज जो दिखाई देती है वह है हाइपरलिंक। कोई पाठ बिल्कुल नहीं।
अपना प्रोजेक्ट चलाने से पहले मैं अपने ग्राफिक लेआउट में यही देखता हूं:
यह तब होता है जब मैं अपना प्रोजेक्ट चलाता हूं:
यहाँ मेरा मुख्य गतिविधि कोड है:
package com.example.rodekruis;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;
public class BWCActivity extends Activity {
TextView HyperLink;
Spanned Text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bwc);
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='https://www.rkz.nl/het_kinderbrandwondencentrum'> Kinderbrandwondencentrum </a>";
textView.setText(Html.fromHtml(text));
}
}
और यह मेरा गतिविधि_मेन कोड है:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.rodekruis.Bezoek" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:src="@drawable/rkz_logo"
android:layout_gravity="left"
android:layout_marginLeft="38dp"/>
<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="364dp" >
<TextView
android:id="@+id/textView"
android:layout_width="244dp"
android:layout_height="276dp"
android:layout_gravity="center"
android:text="@string/title_activity_bwc"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</ScrollView>
</LinearLayout>
1 उत्तर
आपने केवल टेक्स्ट व्यू में लिंक सेट किया है
String text = "<a href='https://www.rkz.nl/het_kinderbrandwondencentrum'> Kinderbrandwondencentrum </a>";
textView.setText(Html.fromHtml(text));
यदि पाठ में पहले से ही लिंक है तो इसका उपयोग करें:
String text = getResources().getString(R.string.title_activity_bwc);
textView.setText(Html.fromHtml(text));
या यदि आप लिंक जोड़ना चाहते हैं तो इसका उपयोग करें:
String text = getResources().getString(R.string.title_activity_bwc);
text += "<a href='https://www.rkz.nl/het_kinderbrandwondencentrum'> Kinderbrandwondencentrum </a>";
textView.setText(Html.fromHtml(text));
संबंधित सवाल
नए सवाल
java
जावा एक उच्च स्तरीय प्रोग्रामिंग भाषा है। इस टैग का उपयोग तब करें जब आपको भाषा का उपयोग करने या समझने में समस्या हो। इस टैग का उपयोग शायद ही कभी किया जाता है और इसका उपयोग अक्सर [वसंत], [वसंत-बूट], [जकार्ता-ई], [Android], [javafx], [हडूप], [श्रेणी] और [मावेन] के साथ किया जाता है।
textView.setText(Html.fromHtml(text));
का उपयोग करके आपxml
के माध्यम से सेट किए गए टेक्स्ट को हटा देते हैंHtml.fromHtml(text)
का उपयोग करना हैR.string.title_activity_bwc
में टेक्स्ट भी चेक करना है शायद कुछ html टैग हैं जो ठीक से बंद नहीं हैं।