Textview break lines

Asked

Viewed 11,860 times

0

My code opens a net txt file and puts it in a textview. The problem is that it joins all the lines together. How to break the lines?

Another question is how to delete the tags from the text file and not break the rtmp and rtmpe links. since with http there is no problem when converting to link

package com.tvmix.read; 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView; 

   public class ReadFileAssetsActivity extends Activity {
    TextView textMsg;
    final String textSource = "https://dl.dropboxusercontent.com/s/w7ga6shmocr23x4/Eventos.txt?dl=0"; 
    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textMsg = (TextView) findViewById(R.id.textmsg);
        URL textUrl;
        try {
            textUrl = new URL(textSource);
            BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));
            String StringBuffer;
            String stringText = "";
            while ((StringBuffer = bufferReader.readLine()) != null) {
                stringText += StringBuffer;
            }
            bufferReader.close();
            textMsg.setText(stringText);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            textMsg.setText(e.toString());
        } catch (IOException e) {
            e.printStackTrace();
            textMsg.setText(e.toString());
        }
    }
  • Format the code so we can understand it.

3 answers

1

You should use " n" for tab, if you want to concatenate with other information, you should use the +

1


Missed you concatenate the line break character (\n) every line you read.

Your reading loop would look:

while ((StringBuffer = bufferReader.readLine()) != null) {
    stringText += (StringBuffer + "\n");
}
  • Thanks solved

0

  • Thanks but it’s settled with n

Browser other questions tagged

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