android - data binding to field, displaying matching icon
<p>I have a class <code>WifiManager</code> that holds a Boolean value that represents either <strong>wifi connected</strong> or <strong>wifi disconnected</strong>.</p>

<p>the Boolean field gets updated with a <code>broadcastReceiver</code> I have in that class.</p>

<pre><code>private BroadcastReceiver wifiScanReceiver;

private boolean isWifiConnected = false;

wifiScanReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context c, Intent intent) {
                    // Wifi connected/disconnected
                    NetworkInfo nwInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                    final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                    if (nwInfo.getState().equals(NetworkInfo.State.CONNECTED)) {
                        // wifi connect
                        isWifiConnected = true;
                    } else {
                        // wifi disconnected
                        isWifiConnected = false;
                    }
                }
        };

        context.registerReceiver(wifiScanReceiver, wifiIntentFilter);
</code></pre>

<p>In my <code>MainActivity</code> I have a <code>WifiManager</code> field, and what I want is to do <strong>data binding</strong> that will <strong>change one of the menu items based on the Boolean value</strong> -> if <code>isWifiConnected=false</code> set icon to <code>@drawalbe/xxx</code>, if <code>isWifiConnected=true</code> set icon to <code>@drawalbe/yyy</code>.</p>

<p>Meaning - having sort of a "listener" to changes of the <code>isWifiConnected</code> value, and based on that - set one of the <code>MenuItem</code>'s icon to either <code>@drawalbe/xxx</code> or <code>@drawalbe/yyy</code>.</p>

<p>I know there are tons of ways to do it, from broadcasting an <code>Intent</code> in the <code>BroadcastReceiver</code> and catch it in the <code>MainActivity</code> to just have a <code>Handler</code> running and checking the <code>isWifiConnected</code> every 3 seconds..</p>

<p>What I am <strong>really</strong> looking for is sort of <strong>data binding</strong> with a converter, like you would do in a <strong>MVVM project</strong>.</p>

<p>Is there such a thing in android?</p>