从WebView切换到主视图后,UI事件不起作用

时间:2018-06-15 13:47:20

标签: android uitableview webview uibutton bluetooth-lowenergy

我有一个可以运行的Android应用程序,可以将其内容视图切换到WebView,并在用户关闭Web视图时返回主视图。切换回后,按钮事件不起作用,即使我调用notifyDataSetChanged(),ListView也不会更新。我切换回蓝牙回调内的主视图,并通过在UI线程上运行setContentView来实现。任何想法都将不胜感激。

setContentView(R.layout.activity_main);   <<< EVERYTHING WORKS

setContentView(webView);

setContentView(R.layout.activity_main);   <<< BUTTONS DON’T WORK LIST VIEW DOESN’T UPDATE


BluetoothGattCallback btGattCallback = new BluetoothGattCallback()
{
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
    {
        Log.d(LOGTAG, "onConnectionStateChange; status: " + status + "; newState: " + newState);

        if (newState == BluetoothProfile.STATE_CONNECTED)
        {
            Log.d(LOGTAG, "BT connected");

            gatt.discoverServices();
        }
        else if (newState == BluetoothProfile.STATE_DISCONNECTED)
        {
            Log.d(LOGTAG, "BT disconnected");

            // Go back to user input and scanner select
            runOnUiThread(new Thread(new Runnable()
            {
                public void run()
                {
                    // Clear the scanner list
                    btDeviceList.clear();
                    btDeviceNameList.clear();
                    btDeviceListAdapter.notifyDataSetChanged();

                     // Start looking for a scanner
                    startBTScan();

                    // Go back to the user input view
                    setContentView(R.layout.activity_main);
                }
            }));
        }
        else
        {
            Log.e(LOGTAG, "Unhandled BT state change");
        }
    }

0 个答案:

没有答案