Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give paragraphs in an activity?

I am building an app for an University. As required I am adding paragraphs taking separate TextView for each paragraphs. Is there a way where i can give paragraphs combined. Its just my thought on whether this is possible? Here is the code snippet i worked on.

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry." />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="14dp"
android:inputType="numberSigned"
android:text="+91 12 12345678" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:inputType="phone"
android:text="+91 12 12345678" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:autoLink="email"
android:inputType="textEmailAddress"
android:text="[email protected]" />

Here in my code I want to give the two phone numbers and the email id combined in a single TextView. Is it possible?

like image 453
Web Avatar asked Dec 07 '25 09:12

Web


1 Answers

Try this way,hope this will help you to solve your prorbelm.

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

MyActivity.java

public class MyActivity extends Activity{

    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        textView = (TextView) findViewById(R.id.textView);
        String htmlText = "<p> +91 12 12345678 </p> <p> +91 12 12345678 </p> <p> [email protected] </p>";
        textView.setText(Html.fromHtml(htmlText));
    }
}
like image 58
Haresh Chhelana Avatar answered Dec 09 '25 21:12

Haresh Chhelana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!