Как добавить разрыв строки в Sqlite при отображении данных в TextView - PullRequest
0 голосов
/ 04 марта 2019

Как добавить разрыв строки в Sqlite при отображении данных в TextView?

Попробовал ответы ниже

Как вставить новую строку ("\n ") символ в SQLite?

Символ новой строки \ n в объединении SQLite

Я пытаюсь загрузить данные в текстовое представление из Sqlite, где я хочудобавить разрыв строки.Я пытался \n \\n, но это не работает.

TextView в 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-код

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

public String getText() {
    return content;
}

SQLite

enter image description here

Вывод TextView

enter image description here

1 Ответ

0 голосов
/ 04 марта 2019

вы пытались сделать ваш TextView многострочным?

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

Или в XML, как это:

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