teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

内容の修正

2020/09/18 18:18

投稿

karin10
karin10

スコア34

title CHANGED
File without changes
body CHANGED
@@ -12,118 +12,8 @@
12
12
 
13
13
  ### コード
14
14
 
15
- **RegistActivity.java**
16
- ```
17
- public class RegistActivity extends Activity {
18
15
 
19
- private MySQLiteOpenHelper helper; //MySQLiteOpenHelperクラス
20
- @Override
21
- protected void onCreate(Bundle savedInstanceState) {
22
- super.onCreate(savedInstanceState);
23
16
 
24
- //activity_regist.xmlに作成した内容を画面に表示
25
- setContentView(R.layout.activity_regist);
26
-
27
- //MySQLiteOpenHelperクラスのオブジェクトを作成
28
- helper = new MySQLiteOpenHelper(this);
29
- //ユーザー名入力用EditTextのオブジェクトを取得
30
- EditText useridForm = findViewById(R.id.useridForm);
31
- //目的選択用Spinnerのオブジェクトを取得
32
- Spinner spinner = findViewById(R.id.spinnerPurpose);
33
- //性別選択用Spinnerのオブジェクトを取得
34
- Spinner spinner1 = findViewById(R.id.spinnerSex);
35
- //年齢入力用EditTextのオブジェクトを取得
36
- EditText ageForm = findViewById(R.id.ageForm);
37
- //体重入力用EditTextのオブジェクトを取得
38
- EditText weightForm = findViewById(R.id.weightForm);
39
- //身長入力用EditTextのオブジェクトを取得
40
- EditText heightForm = findViewById(R.id.heightForm);
41
- //活動レベル選択用Spinnerのオブジェクトを取得
42
- Spinner spinner2 = findViewById(R.id.活動レベルForm);
43
-
44
- // 登録ボタン
45
- Button returnButton = findViewById(R.id.registButton);
46
- returnButton.setOnClickListener(new View.OnClickListener() {
47
- @Override
48
- public void onClick(View view2) {
49
-
50
- //Intentクラスのオブジェクトを生成
51
- Intent intent = new Intent();
52
- int id = view2.getId();
53
- switch (id) {
54
- case R.id.registButton ://[登録]ボタンを押したとき
55
- if (registRecord()) { //登録成功
56
- //インテントに文字列「登録しました」を設定
57
- intent.putExtra("SUCCESS_MESSAGE", "登録しました");
58
- //結果 (RESULT_OK、 1Intent) を設定
59
- setResult(RESULT_OK, intent);
60
- } else { //登録失敗
61
- //インテントに文字列「失敗しました」を設定
62
- intent.putExtra("CANCELLED_MESSAGE", "登録に失敗しました");
63
- //結果 (RESULT_CANSELED、 Intent) を設定
64
- setResult(RESULT_CANCELED, intent);
65
- }
66
- break;
67
- }
68
- RegistActivity.this.finish();
69
- }
70
- });
71
- }
72
-
73
- private boolean registRecord() {
74
- //SQLiteDatabaseクラスを取得(書き込み用)
75
- SQLiteDatabase db = helper.getWritableDatabase();
76
- EditText useridForm = this.findViewById(R.id.useridForm);
77
- EditText ageForm = this.findViewById(R.id.ageForm);
78
- EditText weightForm = this.findViewById(R.id.weightForm);
79
- EditText heightForm = this.findViewById(R.id.heightForm);
80
-
81
- // Spinnerオブジェクトを取得
82
- Spinner spinner = findViewById(R.id.spinnerSex);
83
- Spinner spinner1 = findViewById(R.id.活動レベルForm);
84
- Spinner spinner2 = findViewById(R.id.spinnerPurpose);
85
- // 選択されているアイテムを取得
86
- String item = (String) spinner.getSelectedItem();
87
- String item1 = (String) spinner1.getSelectedItem();
88
- String item2 = (String) spinner2.getSelectedItem();
89
-
90
- String strUserId;
91
- strUserId = useridForm.getText().toString();
92
- String strAge;
93
- strAge = ageForm.getText().toString();
94
- String strWeight;
95
- strWeight = weightForm.getText().toString();
96
- String strHeight;
97
- strHeight = heightForm.getText().toString();
98
-
99
-
100
- double age, weight, height;
101
- age = Double.parseDouble(strAge);
102
- weight = Double.parseDouble(strWeight);
103
- height = Double.parseDouble(strHeight);
104
-
105
- //Productsテーブルに登録するレコードの設定準備
106
- ContentValues value = new ContentValues();
107
- value.put("name", strUserId);
108
- value.put("purpose", item2);
109
- value.put("sex", item);
110
- value.put("age", age);
111
- value.put("weight", weight);
112
- value.put("height", height);
113
- value.put("activityLevel", item1);
114
-
115
- //Productsテーブルに登録
116
- boolean judge = db.insert("Products", null, value) != -1 ? true : false;
117
-
118
- //データベースをクローズ
119
- db.close();
120
-
121
- //登録結果情報を返す
122
- return judge;
123
- }
124
- }
125
- ```
126
-
127
17
  **MainActivity.java**
128
18
  ```
129
19
  public class MainActivity extends AppCompatActivity {

3

タイトルの修正

2020/09/18 18:18

投稿

karin10
karin10

スコア34

title CHANGED
@@ -1,1 +1,1 @@
1
- SQliteに保存したデータを1だけ抽出させる方法
1
+ SQliteに保存したデータを1だけ抽出させる方法
body CHANGED
File without changes

2

タイトルの修正

2020/09/18 17:51

投稿

karin10
karin10

スコア34

title CHANGED
@@ -1,1 +1,1 @@
1
- SQliteに保存したデータをtextviewに表示させる方法
1
+ SQliteに保存したデータを1行だけ抽出させる方法
body CHANGED
File without changes

1

画像の追加

2020/09/18 17:49

投稿

karin10
karin10

スコア34

title CHANGED
File without changes
body CHANGED
@@ -3,15 +3,13 @@
3
3
 
4
4
  対象のtextviewは"useridForm", "spinnerPurpose", "spinnerSex", "ageForm", "weightForm", "heightForm", "活動レベルForm"の六つあり、それぞれに該当するデータを表示させたいです。
5
5
  ### 分からないこと
6
+
6
7
  複数のtextviewにデータベースの各行のデータを分けて表示させる方法が調べてもわかりませんでした。
8
+
7
9
  ---
10
+ ![activityMain](219fc26a9f6b0780641a0e1257f849a2.png)
11
+ ![activityRegist](4a4c8f09a428c53aab77ff6f0bc574ca.png)
8
12
 
9
- **activityRegist**
10
- [![activityRegist][1]][1]
11
-
12
- **activityMain**
13
- [![activityMain][2]][2]
14
-
15
13
  ### コード
16
14
 
17
15
  **RegistActivity.java**