質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

0回答

2307閲覧

togglebuttonでスキャンのON OFFを切り替えるにはどうすればいいですか?

sinatose

総合スコア14

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2015/12/02 10:24

onResumeとonPauseに何かすればいいのですか?
アクティビティの流れ方は分かったのですが、行き来をどうすればいいのかわからなかったです。よければご教授お願いします。

public class MainActivity extends AppCompatActivity implements BeaconConsumer {
// TextView textView;
private BeaconManager beaconManager;
public static final String IBEACON_FORMAT = "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24";

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_my); final ImageView imageView = (ImageView)findViewById(R.id.imageView1); imageView.setImageResource(R.mipmap.ic_launcher); final TextView[] textView = new TextView[1]; ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButton); tb.setTextOff("Stop"); tb.setTextOn("Scan"); tb.setChecked(true); tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked == true) { } else { } textView[0] = (TextView) findViewById(R.id.textView); textView[0].setText(isChecked ? "もう一度探す" : "ビーコンを探しています・・・"); imageView.setImageResource(isChecked ? R.mipmap.ic_launcher : R.mipmap.ic_android); //Toast.makeText(MainActivity.this,"It will start the scan", Toast.LENGTH_SHORT).show(); Log.d(isChecked ? "OnCheckedChangeListenerが呼ばれました(OFF)。" : "OnCheckedChangeListenerが呼ばれました。(ON)", "ToggleButton"); } }); beaconManager = BeaconManager.getInstanceForApplication(this); beaconManager.getBeaconParsers() .add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT)); } @Override protected void onStart(){ super.onStart(); } @Override protected void onResume() { super.onResume(); beaconManager.bind(this); } @Override protected void onPause() { super.onPause(); beaconManager.unbind(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onBeaconServiceConnect() { beaconManager.setRangeNotifier(new RangeNotifier() { Handler mHandler = new Handler(); TextView textView; @Override public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) { for (final Beacon beacon : beacons) { Log.d("MyActivity", "UUID:" + beacon.getId1() + ", major:" + beacon.getId2() + ", minor:" + beacon.getId3() + ", Distance:" + beacon.getDistance() + ",BluetoothName:" + beacon.getBluetoothName() + ",TxPower:" + beacon.getTxPower() ); new Thread(new Runnable() { public void run() { //Handlerにpost mHandler.post(new Runnable() { public void run() { //Viewを操作する処理を記述 textView = (TextView) findViewById(R.id.uuid); textView.setText("UUID:" + beacon.getId1()); textView = (TextView) findViewById(R.id.major); textView.setText("major:" + beacon.getId2()); textView = (TextView) findViewById(R.id.minor); textView.setText("minor:" + beacon.getId3()); textView = (TextView) findViewById(R.id.distance); textView.setText("Distance:" + beacon.getDistance()); ImageView imageView = (ImageView)findViewById(R.id.imageView2); imageView.setImageResource(R.mipmap.ic_launcher); } }); } }).start(); } } });

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問