1

How to add a line breaker in Sqlite while showing data in TextView?

Tried below answers

How to insert a new line ("\n") character in SQLite?

New Line character \n in SQLite concatenate

I am trying to load data into textview from Sqlite, where i want to add line break. I tried \n \\n but that is not working.

TextView in android

 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/direction_card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardElevation="10dp"
        card_view:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FFFFFF"
                android:fontFamily="@font/lato_bold_italic"
                android:minHeight="40dp"
                android:padding="8sp"

                android:text="Title"
                android:textAlignment="center"
                android:textColor="@color/title_color_book_detail_activity"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="5dp"
                android:layout_marginBottom="16dp"
                android:fontFamily="@font/merriweather_bold_italic"
                android:gravity="fill"
                android:singleLine="false"
                android:text="content"
                android:textAlignment="gravity"
                android:textColor="@color/lightslategray_book_content_color2"
                android:textSize="18sp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>

Java Code

Spanned sp = Html.fromHtml(currentText.getText());
    content.setText(sp);
    content.setSingleLine(false);

public String getText() {
    return content;
}

SQLite

enter image description here

TextView Output

enter image description here

1 Answers1

0

have you tried making your TextView multiline?

final TextView nline = new TextView(this);
nline.setSingleLine(false);

Or in XML like this:

<TextView android:id="@+id/your_id"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:singleLine="false"              
        android:text="Johar Mor, Gulistan-e-Johar, \nKarachi" >
    </TextView> 
Lukas Novicky
  • 921
  • 1
  • 19
  • 44
  • so you must show your XML for TextView and your code - otherwise, we are just guessing here – Lukas Novicky Mar 04 '19 at 11:00
  • So, I assume we are talking about second TextView. If it still does not work, I would first made a clean build: Build -> clean project Sometimes AS catches some crap. If that do not help, I would manually put String with new line marker in it, to check if TextView itself works properly - if so, problem is with String from SQL. – Lukas Novicky Mar 04 '19 at 11:07
  • Tried by putting manual string that is working! but when i am trying to load from `SQLite` that is not working...! –  Mar 04 '19 at 11:14
  • please, debug, and check you result from SQLite. It clearly means that SQLite data are corrupted – Lukas Novicky Mar 04 '19 at 11:18