Thursday, January 12, 2012

Android: When scroll the listview, it flickers (How to remove)

You set background image of your listview to either some image or transparent (translucent).
When you scroll down/up, the listview will flicker, blink, or turns black.

This is how to remove:

Before:

              <ListView
                            android:id="@+id/listview"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@color/translucent_heavyGray"
              />

After:


              <ListView
                            android:id="@+id/listview"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@color/translucent_heavyGray"
                            android:cacheColorHint="#00000000"
              />


android:cacheColorHint="#00000000" will solve the problem.

Thursday, January 5, 2012

Android String to long

Android from String to long

String sNum = "99999999";
long lNum = 0;
try {
   lNum = Long.parseLong(sNum);
} catch(NumberFormatException nfe) {
   Log.e("TAG", "Could not parse " + nfe);
}

Android String to double

Android from String to double

       String sNum = "9.9";
       double dNum = 0;
       try {
              dNum = Double.parseDouble(sNum);
       } catch(NumberFormatException nfe) {
          Log.e("TAG", "Could not parse " + nfe);
       }

                    

Android String to float

Android from String to float  
       String sNum = "9.9";
       float fNum = 0;
       try {
              fNum = Float.parseFloat(sNum);
       } catch(NumberFormatException nfe) {
          Log.e("TAG", "Could not parse " + nfe);
       }

Android String to int

Android from String to int

 
              String sNum = "9";
              int iNum = 0;
              try {
                            iNum = Integer.parseInt(sNum);
              } catch(NumberFormatException nfe) {
                 Log.e("TAG", "Could not parse " + nfe);
              }