androidアプリ製作中です。
SQLiteを使用してデータを読み込もうとしていますが、
次の行に行かず、一つのフィールドに書き込んでしまいます。
ソースはこうです。
xml
1<?xml version="1.0" encoding="utf-8"?> 2 3<android.support.v4.widget.DrawerLayout 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:id="@+id/drawer_layout" 7 xmlns:android="http://schemas.android.com/apk/res/android" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent"> 10 11 <ScrollView 12 android:layout_width="match_parent" 13 android:layout_height="match_parent"> 14 15 16 17 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 18 xmlns:app="http://schemas.android.com/apk/res-auto" 19 xmlns:tools="http://schemas.android.com/tools" 20 android:layout_width="match_parent" 21 android:layout_height="match_parent" 22 tools:context=".MainActivity"> 23 24 <LinearLayout 25 android:id="@+id/liner" 26 android:layout_width="match_parent" 27 android:layout_height="50dp"> 28 29 <EditText 30 android:id="@+id/name" 31 android:layout_width="150dp" 32 android:layout_height="40dp" 33 android:ems="10" 34 android:inputType="text" 35 app:layout_constraintStart_toStartOf="@id/liner" /> 36 /> 37 38 <EditText 39 android:id="@+id/price" 40 android:layout_width="50dp" 41 android:layout_height="40dp" 42 android:ems="10" 43 android:inputType="text" 44 app:layout_constraintLeft_toRightOf="@+id/name" /> 45 46 47 <Button 48 android:id="@+id/Btn" 49 android:layout_width="60dp" 50 android:layout_height="50dp" 51 android:layout_alignParentRight="true" 52 android:text="詳細" 53 app:layout_constraintRight_toRightOf="@id/liner" 54 app:layout_constraintEnd_toEndOf="@id/liner"/> 55 56 </LinearLayout> 57 58 </android.support.constraint.ConstraintLayout> 59 60 61 </ScrollView> 62 63 64</android.support.v4.widget.DrawerLayout>
問題になっているJavaです。(テスト中のため、title,scoreとなっています。)
java
1 SQLiteDatabase db = helper.getReadableDatabase(); 2 Cursor cursor = db.query( 3 "testdb", 4 new String[]{"title", "score"}, 5 null, 6 null, 7 null, 8 null, 9 null 10 ); 11 12 cursor.moveToFirst(); 13 StringBuilder sName = new StringBuilder(); 14 StringBuilder sPrice = new StringBuilder(); 15 16 17 for (int i = 0; i < cursor.getCount(); i++) { 18// viewName.setText(cursor[i][0].getString()); 19// viewPrice.setText(cursor[i][1].getInt()); 20// cursor.moveToNext(); 21 sName.append(cursor.getString(0)); 22 23 sPrice.append(cursor.getInt(1)); 24 25 sName.append("\n\n"); 26 cursor.moveToNext(); 27 28 } 29 30 cursor.close(); 31 32 viewName.setText(sName.toString()); 33 viewPrice.setText(sPrice.toString());
「参考サイト」
上記のサイトのように複数行にデータを入れ込みたいです。
それと、詳細ボタンを右端に設定したいのですが、
色々試行錯誤しても解決できませんでした。
こちらも助言を頂けるとたすかります。
「参考にしたサイト」
よろしくお願いします。
追記
スクロールもできるようにしたいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/10 15:17
2019/02/10 15:36