質問編集履歴
1
ソースコードを<code>で記述
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
他クラスのオブジェクト(Button)へのアクセスに
|
1
|
+
他クラスのオブジェクト(Button)へのアクセス(Alt Beacon LibraryでBeacon受信時のみボタンをEnableにする方法)
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
MainActivityクラスにあるボタンを、
|
2
2
|
他クラスから有効・無効を設定できるように、
|
3
3
|
以下のようにstaticなオブジェクトに設定し、
|
4
|
-
|
4
|
+
```ここに言語を入力
|
5
5
|
public class MainActivity extends AppCompatActivity {
|
6
6
|
public static Button entButton;
|
7
7
|
|
@@ -11,15 +11,15 @@
|
|
11
11
|
entButton = (Button) findViewById(R.id.buttonENT);
|
12
12
|
}
|
13
13
|
}
|
14
|
-
|
14
|
+
```
|
15
15
|
Alt Beacon LibraryというBluetoothのBeaconを受信するLibraryを使用して、
|
16
16
|
受信しているBeacon数を取得するモジュール内で、
|
17
17
|
Beaconを受信したときは、ButtonをEnableに、
|
18
|
-
受信できないときは、Buttonを
|
18
|
+
受信できないときは、ButtonをDisableにするような処理を書きました。
|
19
|
-
|
19
|
+
```ここに言語を入力
|
20
20
|
public class RangingActivity extends Activity implements BeaconConsumer {
|
21
21
|
・・・
|
22
|
-
|
22
|
+
@Override
|
23
23
|
public void onBeaconServiceConnect() {
|
24
24
|
RangeNotifier rangeNotifier = new RangeNotifier() {
|
25
25
|
@Override
|
@@ -33,6 +33,7 @@
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
・・・
|
36
|
+
```
|
36
37
|
すると、起動時はBeaconの状態に応じてEnable/Disableは正常に動作するのですが、
|
37
38
|
Beacon状態が変化したとき(Enable→Disable もしくは Disable→Enable)に、
|
38
39
|
アプリがCrashして落ちます。
|
@@ -43,8 +44,7 @@
|
|
43
44
|
|
44
45
|
さらに、RangingActivityクラスに2つのボタンを追加し、
|
45
46
|
それぞれのボタンを押したときに、
|
46
|
-
MainActivity.entButton.setEnabled(true);
|
47
|
-
MainActivity.entButton.setEnabled(false);
|
47
|
+
MainActivity.entButton.setEnabled(true);とMainActivity.entButton.setEnabled(false);
|
48
48
|
を実行するようにしたところ、
|
49
49
|
ボタンのクリックにより、MainActivityクラスのボタンの
|
50
50
|
有効・無効を正常に切り替えることが出来ました。
|