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

質問編集履歴

2

ソースの記載

2020/02/12 07:29

投稿

watchdogs
watchdogs

スコア54

title CHANGED
File without changes
body CHANGED
@@ -1,52 +1,152 @@
1
1
  [ANDROID]SEEKBARから得た変数を取り出し引数として式に組み込みたいのですが、
2
+ 現状SEEKBARを2つ作り各々の数値を表示しています。
3
+ やりたいこととして、
2
- .XMLへIDを設定した後MAIN.javaソーにエラが出ます。
4
+ これら数値の足し算を行いテキトバに表示したいです。
3
- エラーは、式の開始が不正、;が無い、)が無い、文ではない、型の開始が不正です
4
- など出てきます。
5
+ 下記にソースを添付します。
6
+ 現状のプログラムではエラーは無いのですが、
7
+ シミュレータが動きません。
5
- どこをどうのように治してよいらないので、
8
+ どこをどうしてよいか教えて頂けると助ります。
6
- 見て頂けますでしょうか
9
+ よろしくお願い致します。
7
10
 
8
- 現在の状況
9
- 下記のURLを参考に進めています。
10
- https://techbooster.org/android/ui/8329/
11
+ //参考URL:https://teratail.com/questions/65725
11
- 差分としては、
12
- ・数値のテキスト表示を挿せる必要が無いためコメントアウトにしています。
13
- ・IDの変数名をrelease2としています。
14
12
 
13
+ //////////.java ソース/////////////
14
+ package com.androidBiginer.seekbar;
15
15
 
16
- .xmlへの記載内容
17
- <SeekBar
18
- android:id="@+id/release2"
19
- android:layout_width="match_parent"
16
+ import androidx.appcompat.app.AppCompatActivity;
20
- android:layout_height="wrap_content"
17
+ import android.widget.SeekBar;
21
- android:layout_weight="1"
18
+ import android.widget.TextView;
22
- android:entries="@array/sp_buffersize"
23
- android:visibility="visible" />
24
19
 
25
- .javaへの記載内容
20
+ import android.os.Bundle;
21
+
22
+ public class MainActivity extends AppCompatActivity {
23
+
24
+
26
25
  @Override
27
- public void onCreate(Bundle savedInstanceState) {
26
+ protected void onCreate(Bundle savedInstanceState) {
28
- super.onCreate(savedInstanceState);
27
+ super.onCreate(savedInstanceState);
29
- setContentView(R.layout.activity_setup);
28
+ setContentView(R.layout.activity_main);
30
29
 
31
- final SeekBar sb0 = (SeekBar) findViewById(R.id.release2);
30
+ final SeekBar sb0 = (SeekBar) findViewById(R.id.SeekBar00);
32
- //final TextView tv0 = (TextView)findViewById(R.id.TextView00);
31
+ final TextView tv0 = (TextView) findViewById(R.id.TextView00);
32
+ final SeekBar sb1 = (SeekBar) findViewById(R.id.SeekBar01);
33
+ final TextView tv1 = (TextView) findViewById(R.id.TextView01);
34
+ final TextView tv2 = (TextView) findViewById(R.id.TextView02);
35
+ final String[] x = new String[1];
36
+ final String[] y = new String[1];
33
37
 
34
- // シークバーの初期値をTextViewに表示
35
- //tv0.setText("設定値:"+sb0.getProgress());
36
38
 
37
- sb0.setOnSeekBarChangeListener(
39
+ // シークバー0の初期値をTextViewに表示
40
+ tv0.setText("設定値:" + sb0.getProgress());
38
41
 
42
+ sb0.setOnSeekBarChangeListener(
43
+ new SeekBar.OnSeekBarChangeListener() {
39
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
44
+ public void onProgressChanged(SeekBar seekBar,
45
+ int progress, boolean fromUser) {
40
- //ツマミをドラッグしたときに呼ばれる
46
+ // ツマミをドラッグしたときに呼ばれる
41
- tv0.setText("0"+sb0.getProgress());
47
+ tv0.setText("設定値:" + sb0.getProgress());
48
+ x[0] = String.valueOf(progress);
42
- }
49
+ }
50
+
43
- public void onStartTrackingTouch (SeekBar seekBar){
51
+ public void onStartTrackingTouch(SeekBar seekBar) {
44
- // ツマミに触れたときに呼ばれる
52
+ // ツマミに触れたときに呼ばれる
45
- }
53
+ }
54
+
46
- public void onStopTrackingTouch (SeekBar seekBar){
55
+ public void onStopTrackingTouch(SeekBar seekBar) {
47
- // ツマミを離したときに呼ばれる
56
+ // ツマミを離したときに呼ばれる
48
- }
57
+ }
58
+ }
49
- });
59
+ );
60
+
61
+
62
+ // シークバー1の初期値をTextViewに表示
63
+ tv1.setText("設定値:" + sb1.getProgress());
64
+
65
+ sb1.setOnSeekBarChangeListener(
66
+ new SeekBar.OnSeekBarChangeListener() {
67
+ public void onProgressChanged(SeekBar seekBar,
68
+ int progress, boolean fromUser) {
69
+ // ツマミをドラッグしたときに呼ばれる
70
+ tv1.setText("設定値:" + sb1.getProgress());
71
+ y[0] = String.valueOf(progress);
72
+ //これらの数値を足し合わせてみる
73
+ // tv2.setText("合計値:" + sb1.getProgress());//ここに入れると動く
74
+ }
75
+
76
+ public void onStartTrackingTouch(SeekBar seekBar) {
77
+ // ツマミに触れたときに呼ばれる
78
+ }
79
+
80
+ public void onStopTrackingTouch(SeekBar seekBar) {
81
+ // ツマミを離したときに呼ばれる
82
+ }
83
+ }
84
+ );
85
+
86
+ tv2.setText(String.valueOf(Integer.parseInt(x[0])+Integer.parseInt(y[0])));
87
+
88
+
89
+ }
50
90
  }
51
91
 
92
+
93
+ ///////.xml ソース/////////
94
+ <?xml version="1.0" encoding="utf-8"?>
95
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
96
+ xmlns:app="http://schemas.android.com/apk/res-auto"
97
+ xmlns:tools="http://schemas.android.com/tools"
98
+ android:layout_width="match_parent"
99
+ android:layout_height="match_parent"
100
+ tools:context=".MainActivity">
101
+
102
+
52
- よろしくお願い致します。
103
+ <TextView
104
+ android:id="@+id/TextView00"
105
+ android:layout_width="fill_parent"
106
+ android:layout_height="wrap_content"
107
+ android:layout_marginBottom="55dp"
108
+ android:text="設定値表示"
109
+ app:layout_constraintBottom_toTopOf="@+id/SeekBar00"
110
+ app:layout_constraintStart_toStartOf="parent" />
111
+
112
+ <SeekBar
113
+ android:id="@+id/SeekBar01"
114
+ android:layout_width="match_parent"
115
+ android:layout_height="wrap_content"
116
+ android:layout_marginBottom="405dp"
117
+ android:max="100"
118
+ android:progress="25"
119
+ app:layout_constraintBottom_toBottomOf="parent"
120
+ tools:layout_editor_absoluteX="-54dp" />
121
+
122
+ <TextView
123
+ android:id="@+id/TextView01"
124
+ android:layout_width="fill_parent"
125
+ android:layout_height="wrap_content"
126
+ android:layout_marginBottom="41dp"
127
+ android:text="設定値表示2"
128
+ app:layout_constraintBottom_toTopOf="@+id/SeekBar01"
129
+ app:layout_constraintEnd_toEndOf="parent"
130
+ app:layout_constraintStart_toStartOf="parent" />
131
+
132
+ <SeekBar
133
+ android:id="@+id/SeekBar00"
134
+ android:layout_width="match_parent"
135
+ android:layout_height="wrap_content"
136
+ android:layout_marginBottom="73dp"
137
+ android:max="100"
138
+ android:progress="25"
139
+ app:layout_constraintBottom_toTopOf="@+id/TextView01"
140
+ app:layout_constraintEnd_toEndOf="parent"
141
+ app:layout_constraintStart_toStartOf="parent" />
142
+
143
+ <TextView
144
+ android:id="@+id/TextView02"
145
+ android:layout_width="fill_parent"
146
+ android:layout_height="wrap_content"
147
+ android:layout_marginBottom="240dp"
148
+ android:text="合計"
149
+ app:layout_constraintBottom_toBottomOf="parent"
150
+ app:layout_constraintEnd_toEndOf="parent"
151
+ app:layout_constraintHorizontal_bias="0.0"
152
+ app:layout_constraintStart_toStartOf="parent" />

1

ソースをアップロードしました。

2020/02/12 07:29

投稿

watchdogs
watchdogs

スコア54

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,52 @@
1
1
  [ANDROID]SEEKBARから得た変数を取り出し引数として式に組み込みたいのですが、
2
- .XMLへIDを設定した後のMAIN.javaソースの書き方わかりせん
2
+ .XMLへIDを設定した後のMAIN.javaソースにエラー
3
+ エラーは、式の開始が不正、;が無い、)が無い、文ではない、型の開始が不正です
4
+ など出てきます。
3
- ネット情報だけではわからず困ってます。
5
+ どこをどうのように治してよいのかわからので、
4
- 教えて頂けますでしょうか。
6
+ て頂けますでしょうか。
5
7
 
8
+ 現在の状況
9
+ 下記のURLを参考に進めています。
10
+ https://techbooster.org/android/ui/8329/
11
+ 差分としては、
12
+ ・数値のテキスト表示を挿せる必要が無いためコメントアウトにしています。
13
+ ・IDの変数名をrelease2としています。
14
+
15
+
16
+ .xmlへの記載内容
17
+ <SeekBar
18
+ android:id="@+id/release2"
19
+ android:layout_width="match_parent"
20
+ android:layout_height="wrap_content"
21
+ android:layout_weight="1"
22
+ android:entries="@array/sp_buffersize"
23
+ android:visibility="visible" />
24
+
25
+ .javaへの記載内容
26
+ @Override
27
+ public void onCreate(Bundle savedInstanceState) {
28
+ super.onCreate(savedInstanceState);
29
+ setContentView(R.layout.activity_setup);
30
+
31
+ final SeekBar sb0 = (SeekBar) findViewById(R.id.release2);
32
+ //final TextView tv0 = (TextView)findViewById(R.id.TextView00);
33
+
34
+ // シークバーの初期値をTextViewに表示
35
+ //tv0.setText("設定値:"+sb0.getProgress());
36
+
37
+ sb0.setOnSeekBarChangeListener(
38
+
39
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
40
+ //ツマミをドラッグしたときに呼ばれる
41
+ tv0.setText("0"+sb0.getProgress());
42
+ }
43
+ public void onStartTrackingTouch (SeekBar seekBar){
44
+ // ツマミに触れたときに呼ばれる
45
+ }
46
+ public void onStopTrackingTouch (SeekBar seekBar){
47
+ // ツマミを離したときに呼ばれる
48
+ }
49
+ });
50
+ }
51
+
6
52
  よろしくお願い致します。