简体   繁体   中英

How do I switch layout when connected to a Bluetooth device in a Handler?

So I would like to change the layout once i'm successfully connected to a Bluetooth device. I would like to do this in my Handler, but I don't know how. As you can see in my Handler code below , I've tried this in my case BTHandler.STATE_CONNECTED: (this is just copied from BluetoothChat) but I dont know how.

private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case Constants.MESSAGE_STATE_CHANGE:
                    switch (msg.arg1) {
                        case BTHandler.STATE_CONNECTED:
                            setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
                            mConversationArrayAdapter.clear();
                            break;
                        case BTHandler.STATE_CONNECTING:
                            Toast.makeText(getApplicationContext(), "Connecting…", Toast.LENGTH_SHORT).show();
                            Log.v("Log", "connecting");
                            break;
                        case BTHandler.STATE_LISTEN:
                        case BTHandler.STATE_NONE:
                            Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_LONG).show();
                            Log.v("Log", "connected");
                            break;
                    }
            }
        }
    };

Solved the problem by myself.

guiHandler(Constants.CONNECTION_STATUS, Constants.STATE_CONNECTED, "");

This is written in my run method that's inside a ConnectThread .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM