質問編集履歴
9
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
本文
|
2
2
|
うまく動くようになったので改善できるところを教えてください。
|
3
3
|
(例外は発生しているか試しました)
|
4
|
+
```Java
|
4
5
|
package com.mycompany.myappdiceplus;
|
5
6
|
import android.app.*;
|
6
7
|
import android.os.*;
|
@@ -87,6 +88,7 @@
|
|
87
88
|
super.onDestroy();
|
88
89
|
}
|
89
90
|
}
|
91
|
+
```
|
90
92
|
直る前の文
|
91
93
|
結果:成功か失敗(右の合計=乱数,乱数…)
|
92
94
|
と表示したいのですが、
|
8
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,77 +13,80 @@
|
|
13
13
|
import android.widget.AutoCompleteTextView.*;
|
14
14
|
|
15
15
|
public class MainActivity extends Activity{
|
16
|
-
MediaPlayer SE;
|
16
|
+
MediaPlayer SE;
|
17
|
-
protected void onCreate(Bundle savedInstanceState){
|
18
|
-
super.onCreate(savedInstanceState);
|
19
|
-
setContentView(R.layout.main);
|
20
|
-
Button button=(Button)findViewById(R.id.bn);
|
21
|
-
button.setOnClickListener(new OnClickListener(){
|
22
|
-
public void onClick(View Vector){
|
23
17
|
|
18
|
+
|
19
|
+
protected void onCreate(Bundle savedInstanceState){
|
20
|
+
super.onCreate(savedInstanceState);
|
21
|
+
setContentView(R.layout.main);
|
22
|
+
Button button=(Button)findViewById(R.id.bn);
|
23
|
+
button.setOnClickListener(new OnClickListener(){
|
24
|
+
public void onClick(View Vector){
|
25
|
+
|
24
|
-
final EditText DC=(EditText)findViewById(R.id.Dc);
|
26
|
+
final EditText DC=(EditText)findViewById(R.id.Dc);
|
25
|
-
TextView math=(TextView)findViewById(R.id.text);
|
27
|
+
TextView math=(TextView)findViewById(R.id.text);
|
26
|
-
math.setText("???");
|
28
|
+
math.setText("???");
|
27
|
-
final EditText MAX=(EditText)findViewById(R.id.MAX);
|
29
|
+
final EditText MAX=(EditText)findViewById(R.id.MAX);
|
28
|
-
final EditText kai=(EditText)findViewById(R.id.math);
|
30
|
+
final EditText kai=(EditText)findViewById(R.id.math);
|
29
|
-
SE.start();
|
31
|
+
SE.start();
|
30
|
-
|
31
|
-
int max=0;
|
32
|
+
int max=0;
|
32
|
-
int dice = 0;
|
33
|
+
int dice = 0;
|
33
|
-
|
34
|
+
|
34
|
-
int kaisu=0;
|
35
|
+
int kaisu=0;
|
35
|
-
|
36
|
+
|
37
|
+
|
36
|
-
max=Integer.parseInt(MAX.getText().toString());
|
38
|
+
max=Integer.parseInt(MAX.getText().toString());
|
37
|
-
dice=Integer.parseInt(DC.getText().toString());
|
39
|
+
dice=Integer.parseInt(DC.getText().toString());
|
38
|
-
kaisu=Integer.parseInt(kai.getText().toString());
|
40
|
+
kaisu=Integer.parseInt(kai.getText().toString());
|
39
|
-
try
|
41
|
+
try
|
42
|
+
{
|
40
|
-
Thread.sleep(1500);
|
43
|
+
Thread.sleep(1500);
|
41
|
-
}
|
44
|
+
}
|
42
|
-
catch (InterruptedException e)
|
45
|
+
catch (InterruptedException e)
|
46
|
+
{
|
43
|
-
e.printStackTrace();
|
47
|
+
e.printStackTrace();
|
44
|
-
System.exit(1);
|
48
|
+
System.exit(1);
|
45
|
-
}
|
49
|
+
}
|
46
|
-
//元々ここにint kaisu-1;があった
|
47
|
-
int[] sum = new int[kaisu];
|
50
|
+
int[] sum = new int[kaisu];
|
48
|
-
StringBuilder strings=new StringBuilder();
|
51
|
+
StringBuilder strings=new StringBuilder();
|
49
|
-
int Random = 0;
|
52
|
+
int Random = 0;
|
50
|
-
|
53
|
+
|
51
|
-
int dex=sum.length;
|
54
|
+
int dex=sum.length;
|
52
|
-
dex--;
|
55
|
+
dex--;
|
53
|
-
for(int i=0;i<=dex;i++){
|
56
|
+
for(int i=0;i<=dex;i++){
|
54
|
-
sum[i]=new Random().nextInt(max);
|
57
|
+
sum[i]=new Random().nextInt(max);
|
55
|
-
Random+=sum[i];
|
58
|
+
Random+=sum[i];
|
56
|
-
}
|
59
|
+
}
|
57
|
-
strings.append(Random <= dice ? "成功(" : "失敗(");
|
60
|
+
strings.append(Random <= dice ? "成功(" : "失敗(");
|
58
61
|
strings.append(Random).append("=");
|
59
62
|
|
60
|
-
for(int index:sum){
|
63
|
+
for(int index:sum){
|
61
64
|
strings.append(index);
|
62
65
|
strings.append(",");
|
63
|
-
}
|
66
|
+
}
|
64
|
-
strings.append(")");
|
67
|
+
strings.append(")");
|
65
68
|
|
66
|
-
String ans=strings.toString();
|
69
|
+
String ans=strings.toString();
|
67
|
-
math.setText(ans);
|
70
|
+
math.setText(ans);
|
68
|
-
}
|
71
|
+
}
|
69
|
-
});
|
72
|
+
});
|
70
|
-
}
|
73
|
+
}
|
71
74
|
|
72
|
-
@Override
|
75
|
+
@Override
|
73
|
-
protected void onResume()
|
76
|
+
protected void onResume()
|
74
|
-
{
|
77
|
+
{
|
75
|
-
super.onResume();
|
78
|
+
super.onResume();
|
76
|
-
SE = MediaPlayer.create(this, R.raw.niconico);
|
79
|
+
SE = MediaPlayer.create(this, R.raw.niconico);
|
80
|
+
|
81
|
+
}
|
77
82
|
|
83
|
+
@Override
|
84
|
+
protected void onDestroy()
|
85
|
+
{
|
86
|
+
onStop();
|
87
|
+
super.onDestroy();
|
88
|
+
}
|
78
89
|
}
|
79
|
-
|
80
|
-
@Override
|
81
|
-
protected void onDestroy()
|
82
|
-
{
|
83
|
-
onStop();
|
84
|
-
super.onDestroy();
|
85
|
-
}
|
86
|
-
}
|
87
90
|
直る前の文
|
88
91
|
結果:成功か失敗(右の合計=乱数,乱数…)
|
89
92
|
と表示したいのですが、
|
7
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,28 +54,15 @@
|
|
54
54
|
sum[i]=new Random().nextInt(max);
|
55
55
|
Random+=sum[i];
|
56
56
|
}
|
57
|
-
|
58
|
-
|
57
|
+
strings.append(Random <= dice ? "成功(" : "失敗(");
|
59
|
-
strings.append("
|
58
|
+
strings.append(Random).append("=");
|
59
|
+
|
60
|
-
|
60
|
+
for(int index:sum){
|
61
|
-
strings.append(
|
61
|
+
strings.append(index);
|
62
|
-
strings.append("=");
|
63
|
-
for(int i:sum){
|
64
|
-
strings.append(i);
|
65
|
-
strings.append(",");
|
62
|
+
strings.append(",");
|
66
63
|
}
|
67
|
-
}else{
|
68
|
-
strings.append("結果");
|
69
|
-
strings.append("失敗(");
|
70
|
-
strings.append(Random);
|
71
|
-
strings.append("=");
|
72
|
-
for (int i:sum){
|
73
|
-
strings.append(i);
|
74
|
-
strings.append(",");
|
75
|
-
}
|
76
|
-
}
|
77
64
|
strings.append(")");
|
78
|
-
|
65
|
+
|
79
66
|
String ans=strings.toString();
|
80
67
|
math.setText(ans);
|
81
68
|
}
|
6
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Androidアプリの無駄な動作を教えてほしい
|
1
|
+
Android用サイコロアプリの無駄な動作を教えてほしい
|
body
CHANGED
File without changes
|
5
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Androidアプリ
|
1
|
+
Androidアプリの無駄な動作を教えてほしい
|
body
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q14157795609
|
2
|
-
にも投稿しましたがteratailにも投稿させて頂きます。
|
3
1
|
本文
|
4
|
-
結果:成功か失敗(右の合計=乱数,乱数…)
|
5
|
-
とのように出しますが、何故か必ず成功になり、次のようになります。
|
6
|
-
結果:成功(0=)
|
7
|
-
|
2
|
+
うまく動くようになったので改善できるところを教えてください。
|
8
3
|
(例外は発生しているか試しました)
|
9
4
|
package com.mycompany.myappdiceplus;
|
10
5
|
import android.app.*;
|
@@ -32,12 +27,12 @@
|
|
32
27
|
final EditText MAX=(EditText)findViewById(R.id.MAX);
|
33
28
|
final EditText kai=(EditText)findViewById(R.id.math);
|
34
29
|
SE.start();
|
30
|
+
|
35
31
|
int max=0;
|
36
32
|
int dice = 0;
|
37
33
|
|
38
34
|
int kaisu=0;
|
39
35
|
|
40
|
-
|
41
36
|
max=Integer.parseInt(MAX.getText().toString());
|
42
37
|
dice=Integer.parseInt(DC.getText().toString());
|
43
38
|
kaisu=Integer.parseInt(kai.getText().toString());
|
@@ -48,7 +43,7 @@
|
|
48
43
|
e.printStackTrace();
|
49
44
|
System.exit(1);
|
50
45
|
}
|
51
|
-
|
46
|
+
//元々ここにint kaisu-1;があった
|
52
47
|
int[] sum = new int[kaisu];
|
53
48
|
StringBuilder strings=new StringBuilder();
|
54
49
|
int Random = 0;
|
@@ -101,4 +96,21 @@
|
|
101
96
|
onStop();
|
102
97
|
super.onDestroy();
|
103
98
|
}
|
104
|
-
}
|
99
|
+
}
|
100
|
+
直る前の文
|
101
|
+
結果:成功か失敗(右の合計=乱数,乱数…)
|
102
|
+
と表示したいのですが、
|
103
|
+
結果:成功(0=)
|
104
|
+
どうしてでしょうか。直し方を教えてください。
|
105
|
+
一部省く…
|
106
|
+
|
107
|
+
try{
|
108
|
+
max=Integer.parseInt(MAX.getText().toString());
|
109
|
+
dice=Integer.parseInt(DC.getText().toString());
|
110
|
+
kaisu=Integer.parseInt(kai.getText().toString());
|
111
|
+
Thread.sleep(1500);
|
112
|
+
}
|
113
|
+
catch (Exception e){
|
114
|
+
}
|
115
|
+
int kaisu-1;
|
116
|
+
…
|
4
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,17 +37,18 @@
|
|
37
37
|
|
38
38
|
int kaisu=0;
|
39
39
|
|
40
|
-
|
40
|
+
|
41
41
|
max=Integer.parseInt(MAX.getText().toString());
|
42
42
|
dice=Integer.parseInt(DC.getText().toString());
|
43
43
|
kaisu=Integer.parseInt(kai.getText().toString());
|
44
|
+
try{
|
44
45
|
Thread.sleep(1500);
|
45
46
|
}
|
46
|
-
catch(
|
47
|
+
catch (InterruptedException e){
|
47
|
-
|
48
|
+
e.printStackTrace();
|
49
|
+
System.exit(1);
|
48
50
|
}
|
49
51
|
|
50
|
-
kaisu-=1;
|
51
52
|
int[] sum = new int[kaisu];
|
52
53
|
StringBuilder strings=new StringBuilder();
|
53
54
|
int Random = 0;
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,10 +32,10 @@
|
|
32
32
|
final EditText MAX=(EditText)findViewById(R.id.MAX);
|
33
33
|
final EditText kai=(EditText)findViewById(R.id.math);
|
34
34
|
SE.start();
|
35
|
-
int max=
|
35
|
+
int max=0;
|
36
|
-
int dice =
|
36
|
+
int dice = 0;
|
37
37
|
|
38
|
-
int kaisu=
|
38
|
+
int kaisu=0;
|
39
39
|
|
40
40
|
try{
|
41
41
|
max=Integer.parseInt(MAX.getText().toString());
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
とのように出しますが、何故か必ず成功になり、次のようになります。
|
6
6
|
結果:成功(0=)
|
7
7
|
どうしてでしょうか。直し方を教えてください。
|
8
|
+
(例外は発生しているか試しました)
|
8
9
|
package com.mycompany.myappdiceplus;
|
9
10
|
import android.app.*;
|
10
11
|
import android.os.*;
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -51,7 +51,8 @@
|
|
51
51
|
StringBuilder strings=new StringBuilder();
|
52
52
|
int Random = 0;
|
53
53
|
|
54
|
-
int dex=sum.length
|
54
|
+
int dex=sum.length;
|
55
|
+
dex--;
|
55
56
|
for(int i=0;i<=dex;i++){
|
56
57
|
sum[i]=new Random().nextInt(max);
|
57
58
|
Random+=sum[i];
|