title: Load different wifi signal strength images based on signal strength in android
body: <p>I am trying to display images (basic images which represent wifi signal strength) on my android application. I have tried implementing that with the below code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public View getView(int position, View convertView, ViewGroup parent) {
  
    LayoutInflater inflater = (LayoutInflater) MainActivity.this
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.wifi_row, parent, false);
    S_ID = (TextView) view.findViewById(R.id.SSID);
    BSSID = (TextView) view.findViewById(R.id.BSSID);
    wifi_strength = (ImageView) view.findViewById(R.id.wifi_signal);
    wifi_lock = (ImageView) view.findViewById(R.id.wifi_lock);
    S_ID.setText(my_array.get(position));
    BSSID.setText(wifiScanList.get(position).BSSID);
    
    
    int current_level = 5;
    int signal_level = WifiManager.calculateSignalLevel(mainWifiObj
      .getConnectionInfo().getRssi(), current_level);
    int signal_difference = (signal_level * 100) / current_level;
    
    Log.d("Signal_level", String.valueOf(signal_level));
  
    if (signal_difference &gt;= 100) {
     wifi_strength.setImageResource(R.drawable.wifi_signal_4);
    } else if (signal_difference &gt;= 75) {
     wifi_strength.setImageResource(R.drawable.wifi_signal_3);
    } else if (signal_difference &gt;= 50) {
     wifi_strength.setImageResource(R.drawable.wifi_signal_2);
    } else if (signal_difference &gt;= 25) {
     wifi_strength.setImageResource(R.drawable.wifi_signal_1);
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Below is my receiver class</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>protected void onPause() {
   unregisterReceiver(wifiReciever);
   super.onPause();
  }
  
  protected void onResume() {
   registerReceiver(wifiReciever, new IntentFilter(
     WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
   super.onResume();
  }
  
  class WifiScanReceiver extends BroadcastReceiver {
   @SuppressLint("UseValueOf")
   public void onReceive(Context c, Intent intent) {
    wifiScanList = mainWifiObj.getScanResults();
    for (int i = 0; i &lt; wifiScanList.size(); i++) {
     my_array.add((wifiScanList.get(i)).SSID);
    }
    myAdapter.notifyDataSetChanged();
   }
  } </code></pre>
  </div>
  </div>
  </p>
  
  <p>But it always display a full signal wifi image even for the weakest wifi network. </p>
  
  <p>Any idea on how to do this?</p>