2.3.3

2017-11-07 4 views
0

コードチュートリアルの説明のようなHTMLコードを入れたいので、 私はHTMLチュートリアルの最後で2.3.3

下記のウェブサイトのリンクのような活動のhtmlコードを表示したいです200以上の例が見つかります。

オンラインエディタでは、各サンプルを自分で編集してテストすることができます。

+0

https://www.w3schools.com/html/tryit.asp?filename = tryhtml_default –

+0

質問は何ですか? – greenapps

+1

@MichaelHancockあなたはフラグ>複製>ボックスにリンクを入れ>をクリックする必要があります質問 –

答えて

0

iは、ボタンショーのhtmlコードの出力.........をクリックしてのTextViewにHTMLコードを表示したい - サチンSrivastava氏

にライブラリの下に追加build.gradleファイル

//for html to text 
compile 'org.jsoup:jsoup:1.8.3' 

TextView txt_htmltext; 
Button btn; 

txt_htmltext = (TextView) findViewById(R.id.txt_htmltext); 
btn = (Button) findViewById(R.id.btn); 

txt_htmltext.setText(R.string.temp_html_text); 

btn.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     txt_htmltext.setText(html2text(txt_htmltext.getText().toString())); 
    } 
}); 

public String html2text(String html) { 
    try { 
     return Jsoup.parse(html).text(); 
    } catch (Exception ignored) { 
     return ""; 
    } 
} 

のres /値/ string.xmlを:

<string name="temp_html_text"><![CDATA[<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>This is a Heading</h1> <p>This is a paragraph.</p> </body> </html>]]></string> 

XMLコード:私はチュートリアルのコード例を作成したい

<LinearLayout 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="3sp"> 

    <TextView 
     android:id="@+id/txt_htmltext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center|left" 
     android:text="@string/temp_html_text"/> 

    <Button 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="html to text"/> 

</LinearLayout> 
+0

は動作していますが、コードは整列していません。あなたは、正確なHTML出力を得るfile1.htmlファイルを作成し、あなたの資産フォルダに入れて、それを呼び出すために、代わりに、

ヘッダータグ

やAndroidで任意のアライメントのような を 使用し、正確な出力を得ることができない –

+0

@SachinSrivastava Webview。 – Dhiren

+0

はいDhirenさん私はそれを使用&正常に多くのおかげでDhirenさん –

1

は、あなたのbuild.gradleファイルにライブラリーの下に

//for html to text 
compile 'org.jsoup:jsoup:1.8.3' 

を追加し、アンドロイドにテキストとしてHTMLコードを取得する方法の下に使用します。

public String html2text(String html) { 
    try { 
     return Jsoup.parse(html).text(); 
    } catch (Exception ignored) { 
     return ""; 
    } 
} 

String myhtmlcode = "<p>its my html code</p>"; 

yourTextView.settext(html2text(myhtmlcode)); 
+0

私のために働いていない –

+0

私はtextviewにhtmlコードを表示したいと思うし、ボタンをクリックしてhtmlコードの出力を表示する......... –

+0

上記のコードをHTMLコードをテキストに変換するだけです。 必要条件を作成する必要があります。その取り扱いが容易です。 – Dhiren

関連する問題