I want to put more than one paragraph in my android xml, do you have how?

Asked

Viewed 424 times

3

I’m trying to do something very simple. I want when the user press the "msg" button to appear a message with at least two short paragraphs just below the button, but I’m finding it difficult to put the information inside a Textview because it doesn’t let me format the text the way I want it and, When I put all the text inside Textview the paragraph gets all broken. Can someone help me?

xml:

 <LinerLayout
 android:layout_width = "match_parent"
 android:layout_height = "wrap_content"
 android:background = "#ddd"
 android:orientation = "vertical">

<Button
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text ="aperte!"
 android:onclick = "imprimirTexto"/>

 <TextView
  android:id = "@+id/textoTextView"
  android:layout_width ="wrap_content"
  android:layout_height = "wrap content"
  android:layout_gravity = "center"/>

 </LinearLayout>

java

public class MainActivity extends Activity{
 private TextView texto;
 public void onCreate(Budle saveInstanceState){
   super.onCreate(saveInstanceState);
   setContentView(R.layout.main);

  texto = (TextView) findViewById(R.id.textoTextView);

}
public void imprimirTexto(View v){
  texto.setText("meus paragrafos ficam aqui");
 }
 }
  • How are you building that message? It’s a Alertdialog? Edith your question and include the xml his.

1 answer

0


Has two possibilities:

  • Add another Textview at the layout and divide the text between the two.
  • Put a value in dp(ex.: 100dp) or match_parent in android:layout_width.
    In the case of the dp the required lines shall be created at the given length in order to display the whole text.
    Use match_parent the necessary lines are created, the length of the layout, in order to present the full text.
  • thank you, it was quite useful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.