0
votes

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''

1
Try \\n instead of \nDreo
thanks for replying @Dreo, i tried \\n it does not work! i also tried \\\n. "\n" this doesn't work too!Amir Dora.
@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.
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

1 Answers

0
votes

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.