0

I'm creating a text view in android studio, the text view is empty by default, it fetches data from mysql database. The text is long and contains the "\n" character for force line breaks. For some reason, the text view is displaying the \n and there isn't any line breaks. Here is my code:

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:singleLine="false"
    android:id="@+id/textView"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:textAlignment="center"
    android:layout_below="@+id/imageView3"
    android:layout_marginTop="70dp"
    android:textColor="#ffffff"
    android:textSize="35sp"
    />

here is the picture of the app showing text with no line break :( https://goo.gl/Cr34Cq

the text in picture is edited in mysql database. it is displayed as it is.

i can also provide java code and mysql database table also.

here is java code that fetches data from mysql database.

    public class Main extends AppCompatActivity {
    //phpconnection declaration
    TextView resultView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    //phpconnection starts from here
    StrictMode.enableDefaults();
    resultView = (TextView) findViewById(R.id.textView);

    getData();

---------------------debug -------------------------------

'Waiting for device. Target device: motorola-xt1033 Uploading file local path: C:\Users\Admin\AndroidStudioProjects\BabyNames(Balochi)\app\build\outputs\apk\app-debug.apk remote path: /data/local/tmp/com.balochibabynames.doradevelopers.babynamesbalochi Installing com.balochibabynames.doradevelopers.babynamesbalochi DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.balochibabynames.doradevelopers.babynamesbalochi" pkg: /data/local/tmp/com.balochibabynames.doradevelopers.babynamesbalochi Success

Launching application: com.balochibabynames.doradevelopers.babynamesbalochi/com.balochibabynames.doradevelopers.babynamesbalochi.Splash. DEVICE SHELL COMMAND: am start -D -n "com.balochibabynames.doradevelopers.babynamesbalochi/com.balochibabynames.doradevelopers.babynamesbalochi.Splash" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.balochibabynames.doradevelopers.babynamesbalochi/.Splash }

Waiting for process: com.balochibabynames.doradevelopers.babynamesbalochi Connected to the target VM, address: 'localhost:8600', transport: 'socket''

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
  • Try \\n instead of \n – Dreo Aug 16 '15 at 19:55
  • thanks for replying @Dreo, i tried \\n it does not work! i also tried \\\n. "\n" this doesn't work too! – Amir Dora. Aug 16 '15 at 19:57
  • 1
    possible duplicate of [How to add a line break in an Android TextView?](http://stackoverflow.com/questions/5382490/how-to-add-a-line-break-in-an-android-textview) – Kristján Aug 16 '15 at 19:58
  • @kristjan no it's not a duplicate of that question. Here the textview is linked to database. and simple textview formating like \n does not work. – Amir Dora. Aug 16 '15 at 20:00
  • For the main issue, log the value of result to see exactly what you're getting. In addition, it looks like you're doing network operations on the main thread, so it's surprising that it's working at all. What version of Android are you testing on? – Daniel Nugent Aug 16 '15 at 22:33
  • i'm testing it on android lollipop! i have also tested the app on jellybean. i also included debug log.. you can see it in main post – Amir Dora. Aug 18 '15 at 15:11

1 Answers1

0

Just a simple stripslashes php code solved the problem! Thanks to myself cause no one else bothered to help here! Thanks to some guys who atleast replied.

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
  • It is great to see that you solved your own problem. Why nobody bothered to help you. It is because you failed to read [ask] . Also your code you provide should be [mcve] And finally you failed to mention in your question and even in your great revalation that the problem was not in java code nor in MySQL, but in **PHP** where you are handling your data. So please take some time and fix your answer in a way it is helpful. And also please mark answers on your questions, so others will not have to look into them and waste their time. – Marek Vitek Jun 19 '17 at 18:14