如何在TextView中显示数据时在Sqlite中添加断路器?
尝试下面的答案
How to insert a new line ("\n") character in SQLite?
New Line character \n in SQLite concatenate
我试图从Sqlite加载数据到textview,我想在其中添加换行符。我试过\n
\\n
,但这不起作用。
Android中的TextView
<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的
TextView输出
你尝试过制作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>