美文网首页
如何动态监听值,保持UI同步

如何动态监听值,保持UI同步

作者: Sunny君907 | 来源:发表于2017-12-15 17:38 被阅读0次

    importandroid.database.ContentObserver;

    getContentResolver().registerContentObserver(Settings.Global.getUriFor(DOZE_WHATSAPP_MODE),false,

    mWhatsAppModeObserver);

    getContentResolver().unregisterContentObserver(mWhatsAppModeObserver);

        private ContentObserver mWhatsAppModeObserver = new ContentObserver(
                new Handler()) {
            public void onChange(boolean selfChange, Uri uri) {
                Log.d(TAG, "mWhatsAppModeObserver:" + uri.toString());
                if (uri.toString().equals(mWhatsappUri)) {
                    Log.d(TAG, "mWhatsAppModeObserver onChange begin ----->");
                    boolean isWhatsapp = mPresenter.isWhatsAppMode();
                    Log.d(TAG, "mWhatsAppModeObserver isWhatsapp:" + isWhatsapp);
                    mWhatsAppSwitch.setChecked(isWhatsapp);
                    mTvWhatsAppSwitchTip.setText(isWhatsapp ? R.string.feature_on : R.string.feature_off);
                    Log.d(TAG, "mWhatsAppModeObserver onChange end----->");
                }
            }
        };

    相关文章

      网友评论

          本文标题:如何动态监听值,保持UI同步

          本文链接:https://www.haomeiwen.com/subject/havdwxtx.html