android - Switch findViewById returns null -


i trying 2 days solve problem. made fragment in made switch enable , disable bluetooth. in main activity wrote:

bluetoothswitch = (switch) findviewbyid(r.id.bluetooth_switch); bluetoothswitch.setonclicklistener(clicked); 

where clicked:

clicked = new buttonclicked(); 

and:

class buttonclicked implements adapterview.onclicklistener {     @override     public void onclick(view view) {         switch (view.getid()) {             case r.id.bluetooth_switch:                 if (bluetoothadapter.isenabled()){                     bluetoothadapter.disable();                     log.d("log", "bluetooth disabled");                 }                 else{                     bluetoothadapter.enable();                     log.d("log", "bluetooth enabled");                 }                 break;             case r.id.buttonsearch:                 arraylistbluetoothdevices.clear();                 startsearching();                 break;             case r.id.discoverable_switch:                 makediscoverable();                 break;             default:                 break;         }     } } 

when run findviewbyid return null...do have idea???

what you're trying won't work - findviewbyid looks view inside activity xml view (r.id.bluetooth_switch) inside fragment's xml.
on this answer code implementation.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -