Convert dip to px in Android
<p>-I had written method to get the pixels from dps but it was not working.giving runtime error.</p>

<p>-Actually i was running this method in separate class and initialized in my Activity class board = new Board(this);
oard.execute(URL);</p>

<p>for running asynchronously.Please help me</p>

<p>public float getpixels(int dp){</p>

<pre><code>    //Resources r = boardContext.getResources();
    //float px = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpis, r.getDisplayMetrics());

     final float scale = this.boardContext.getResources().getDisplayMetrics().density;
        int px = (int) (dp * scale + 0.5f);



    return px;

}
</code></pre>
