発生している問題
AndroidStudio、言語はJavaでアプリ作成を行っています。
SQLiteで取得した改行コード(\n)を含むデータをTextViewに設定すると、改行はされているようですが、途切れて一行目しか表示されません。
該当のソースコード
■SqliteOpenHelper.java
java
1db.execSQL("INSERT INTO cdVersionTbl (titleCd, versionCd, special, hasFlg, favoriteFlg) VALUES(17, 2, '1. MV\n2. メイキング映像', 0, 0);");
■Activity
java
1TextView textSpecial = new TextView(getActivity()); 2String text = record.get(CLM_SPECIAL); //デバッグ: text = 1. MV\n2. メイキング映像 3textSpecial.setText(text); 4textSpecial.setTextSize(18); 5textSpecial.setPadding(50, 0, 0, 0); 6textSpecial.setLayoutParams(new LinearLayout.LayoutParams( 7 LinearLayout.LayoutParams.MATCH_PARENT, 8 LinearLayout.LayoutParams.WRAP_CONTENT)); 9 layoutSpecialContents.addView(textSpecial);
■レイアウト
xml
1<LinearLayout 2 android:id="@+id/layout_special_contents" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:layout_marginBottom="20dp" 6 android:orientation="vertical"> 7 8 <TextView 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:text="@string/lblSpecial" 12 android:textColor="@color/colorPrimary" 13 android:textSize="18sp" />
試したこと
1. SQLiteから取得する際に改行コードがエスケープされているのかと思い、改行コードを置換してみましたが、変わりありませんでした。
java
1textSpecial.setText(text.replace("\\n", "\n")); 2 3textSpecial.setText(text.replace("\r\n", "\n"));
2. 以下のコードを追加したところ、全文表示されるようにはなりましたが、改行がされません。(「1. MV 2. メイキング映像」)
java
1textSpecial.setInputType(InputType.TYPE_CLASS_TEXT);
3. レイアウトの問題で表示されていないだけかとも思いましたが、以下のコードでは全文表示されます。
java
1TextView textSpecial = new TextView(getActivity()); 2textSpecial.setText("あああ\nいいい\nううう");
宜しくお願い致します。

回答1件
あなたの回答
tips
プレビュー