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

質問編集履歴

14

解決しました。

2017/05/03 20:21

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -11,40 +11,39 @@
11
11
  setContentView(R.layout.activity_main);
12
12
  }
13
13
  ```
14
+ //解決したコード
14
15
  ```java
15
- public void favorite() {
16
- username="na";
17
- spinnerItems[]= {"GPSの現在地", "新規登録/ログイン","googlemapで検索","表示画面を登録" + str};
18
- }
19
- ```
20
- ```java
21
- public void favorite() {
22
- username="na";
23
- while (mov) {
24
-
25
- String s = String.format(",\"%s\"", c.getString(0));
26
- str = str + s;
27
- mov = c.moveToNext();
28
- }
29
- spinnerItems[]= {"GPSの現在地", "新規登録/ログイン","googlemapで検索","表示画面を登録" + str};
30
- System.out.println("\"GPSの現在地\", \"googlemapで検索\",\"表示画面を登録\"" + str);
31
- }
32
- //上記のコードを実行するとこのように、表示されました。
33
- //I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
34
-
35
- }
36
- ```
37
- //いただいたアドバイスを元に、配列に代入していた、要素をArrayListに
38
- 代入して、String spinnerItems[]を初期化する場所でArrayListから取得した要素を代入できないか試してみます。
39
16
  //クラス変数
40
- ArrayList<String> array = new ArrayList<String>();
17
+ String spinnerItems[];
18
+ //favoriteメソッド
19
+ public void favorite() {
41
20
 
42
- //favorite()
43
- array.add(new String("GPSの現在地"));
44
- array.add(new String("新規登録/ログイン"));
45
- array.add(new String("googlemapで検索"));
46
- array.add(new String("表示画面を登録"));
47
21
 
22
+ MyOpenHelper helper = new MyOpenHelper(LocationActivity.this);
23
+ SQLiteDatabase db = helper.getReadableDatabase();
24
+
25
+ String sql = "select placename from favorite where username = '" + username + "';";
26
+
27
+ Cursor c = db.rawQuery(sql, null);
28
+ int count = c.getCount();
29
+
30
+ spinnerItems = new String[count + 4];
31
+ spinnerItems[0] = "GPSの現在地";
32
+ spinnerItems[1] = "新規登録/ログイン";
33
+ spinnerItems[2] = "googlemapで登録";
34
+ spinnerItems[3] = "表示画面を登録";
35
+
36
+ boolean mov = c.moveToFirst();
37
+
38
+ int mam=0;
48
- while (mov) {
39
+ while (mov) {
49
- String s = String.format("\"%s\"",c.getString(0));
50
- array.add(new String(s));
40
+ String in=c.getString(0);
41
+ spinnerItems[mam + 4] = in ;
42
+ mov = c.moveToNext();
43
+ mam=mam+1;
44
+ }
45
+ c.close();
46
+ db.close();
47
+ }
48
+
49
+ ```

13

誤字

2017/05/03 20:21

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -46,5 +46,5 @@
46
46
  array.add(new String("表示画面を登録"));
47
47
 
48
48
  while (mov) {
49
- String s = String.format(",\"%s\"", c.getString(0));
49
+ String s = String.format("\"%s\"",c.getString(0));
50
50
  array.add(new String(s));

12

変更

2017/05/03 17:27

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -35,7 +35,7 @@
35
35
  }
36
36
  ```
37
37
  //いただいたアドバイスを元に、配列に代入していた、要素をArrayListに
38
- 変数をArrayListに代入して、String spinnerItems[]を初期化する場所でArrayListから取得した要素を代入できないか試してみます。
38
+ 代入して、String spinnerItems[]を初期化する場所でArrayListから取得した要素を代入できないか試してみます。
39
39
  //クラス変数
40
40
  ArrayList<String> array = new ArrayList<String>();
41
41
 

11

変更

2017/05/03 17:01

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -34,9 +34,11 @@
34
34
 
35
35
  }
36
36
  ```
37
+ //いただいたアドバイスを元に、配列に代入していた、要素をArrayListに
37
- // 要素数を増やすことはできなかったので、変数をArrayListに代入して、String spinnerItems[]を初期化する場所で代入しようと考えます。
38
+ 変数をArrayListに代入して、String spinnerItems[]を初期化する場所でArrayListから取得した要素を代入できないか試してます。
38
39
  //クラス変数
39
40
  ArrayList<String> array = new ArrayList<String>();
41
+
40
42
  //favorite()
41
43
  array.add(new String("GPSの現在地"));
42
44
  array.add(new String("新規登録/ログイン"));
@@ -45,5 +47,4 @@
45
47
 
46
48
  while (mov) {
47
49
  String s = String.format(",\"%s\"", c.getString(0));
48
- array.add(new String(s));
50
+ array.add(new String(s));
49
- をする。

10

誤字

2017/05/03 17:00

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -46,4 +46,4 @@
46
46
  while (mov) {
47
47
  String s = String.format(",\"%s\"", c.getString(0));
48
48
  array.add(new String(s));
49
- して、
49
+ する。

9

説明

2017/05/03 16:52

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -34,15 +34,16 @@
34
34
 
35
35
  }
36
36
  ```
37
+ // 要素数を増やすことはできなかったので、変数をArrayListに代入して、String spinnerItems[]を初期化する場所で代入しようと考えています。
37
38
  //クラス変数
38
39
  ArrayList<String> array = new ArrayList<String>();
39
- //favorite() 要素数を増やすことはできなかったので、
40
+ //favorite()
40
41
  array.add(new String("GPSの現在地"));
41
42
  array.add(new String("新規登録/ログイン"));
42
43
  array.add(new String("googlemapで検索"));
43
44
  array.add(new String("表示画面を登録"));
44
45
 
45
- while (mov) { //これで別に取得できるよね 最後まで
46
+ while (mov) {
46
47
  String s = String.format(",\"%s\"", c.getString(0));
47
48
  array.add(new String(s));
48
49
  をして、

8

説明

2017/05/03 16:32

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -33,4 +33,16 @@
33
33
  //I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
34
34
 
35
35
  }
36
- ```
36
+ ```
37
+ //クラス変数
38
+ ArrayList<String> array = new ArrayList<String>();
39
+ //favorite() 要素数を増やすことはできなかったので、
40
+ array.add(new String("GPSの現在地"));
41
+ array.add(new String("新規登録/ログイン"));
42
+ array.add(new String("googlemapで検索"));
43
+ array.add(new String("表示画面を登録"));
44
+
45
+ while (mov) { //これで別に取得できるよね 最後まで
46
+ String s = String.format(",\"%s\"", c.getString(0));
47
+ array.add(new String(s));
48
+ をして、

7

コードの守勢

2017/05/03 16:29

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -14,6 +14,12 @@
14
14
  ```java
15
15
  public void favorite() {
16
16
  username="na";
17
+ spinnerItems[]= {"GPSの現在地", "新規登録/ログイン","googlemapで検索","表示画面を登録" + str};
18
+ }
19
+ ```
20
+ ```java
21
+ public void favorite() {
22
+ username="na";
17
23
  while (mov) {
18
24
 
19
25
  String s = String.format(",\"%s\"", c.getString(0));

6

誤字

2017/05/03 15:27

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -24,7 +24,7 @@
24
24
  System.out.println("\"GPSの現在地\", \"googlemapで検索\",\"表示画面を登録\"" + str);
25
25
  }
26
26
  //上記のコードを実行するとこのように、表示されました。
27
- //I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","三軒茶屋 サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
27
+ //I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
28
28
 
29
29
  }
30
30
  ```

5

誤字

2017/05/03 14:45

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -24,7 +24,7 @@
24
24
  System.out.println("\"GPSの現在地\", \"googlemapで検索\",\"表示画面を登録\"" + str);
25
25
  }
26
26
  //上記のコードを実行するとこのように、表示されました。
27
- I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","三軒茶屋 サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
27
+ //I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","三軒茶屋 サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
28
28
 
29
29
  }
30
30
  ```

4

誤字

2017/05/03 14:44

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -24,7 +24,7 @@
24
24
  System.out.println("\"GPSの現在地\", \"googlemapで検索\",\"表示画面を登録\"" + str);
25
25
  }
26
26
  //上記のコードを実行するとこのように、表示されました。
27
- I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","三軒茶屋 サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","三軒茶屋 ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
27
+ I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","三軒茶屋 サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
28
28
 
29
29
  }
30
30
  ```

3

コードの修正

2017/05/03 14:44

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -14,6 +14,17 @@
14
14
  ```java
15
15
  public void favorite() {
16
16
  username="na";
17
+ while (mov) {
18
+
17
- spinnerItems[]= {"GPSの現在地", "新規登録/ログイン","googlemapで検索","表示画面を登録" + str};
19
+ String s = String.format(",\"%s\"", c.getString(0));
20
+ str = str + s;
21
+ mov = c.moveToNext();
18
22
  }
23
+ spinnerItems[]= {"GPSの現在地", "新規登録/ログイン","googlemapで検索","表示画面を登録" + str};
24
+ System.out.println("\"GPSの現在地\", \"googlemapで検索\",\"表示画面を登録\"" + str);
25
+ }
26
+ //上記のコードを実行するとこのように、表示されました。
27
+ I/System.out: "GPSの現在地", "googlemapで検索","表示画面を登録","三軒茶屋 サンマルク","サンマルク 左の方に","サンマルク","さんまるく","サンマルクカフェ ","カフェ","三軒茶屋 ビッグエコー","釜製麺","カラオケ館”,"デニーズ","駅"
28
+
29
+ }
19
30
  ```

2

誤字

2017/05/03 14:43

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -4,7 +4,7 @@
4
4
  アドバイスをいただけないでしょうか?
5
5
  ```java
6
6
  String username="ta";
7
- String spinnerItems[]= {"GPSの現在地","新規登録/ログイン","表示画面を登録};
7
+ String spinnerItems[]= {"GPSの現在地","新規登録/ログイン","表示画面を登録"};
8
8
  @Override
9
9
  protected void onCreate(Bundle savedInstanceState) {
10
10
  super.onCreate(savedInstanceState);

1

説明

2017/05/03 14:21

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -9,8 +9,11 @@
9
9
  protected void onCreate(Bundle savedInstanceState) {
10
10
  super.onCreate(savedInstanceState);
11
11
  setContentView(R.layout.activity_main);
12
+ }
12
13
  ```
13
14
  ```java
15
+ public void favorite() {
14
16
  username="na";
15
17
  spinnerItems[]= {"GPSの現在地", "新規登録/ログイン","googlemapで検索","表示画面を登録" + str};
18
+ }
16
19
  ```