title: Use Loader to load listview data in backgroud for smooth scrolling
body: <p>I have a custom listview which has more child views . When I scroll the listview it scrolls very slow leading to avoid the use of the application. I am very much new to android ,please help me how to load the data in background thread , so that the listview scrolls smooth</p>
  
  <p>SearchListActivity.java</p>
  
  <pre><code>public class SearchListActivity extends ListActivity{
  
      String from[];
      static String longClickValue;
      int to[];   
      static String name="",birthdate="",westerZodiac="",turnsAge="",nextBD="",eventType="";
      static Bitmap bitMap=null;
      //CustomCursorAdapter adapter;
      CustomSimpleCursor adapter;
  
      TextView emptyView;
      Cursor cursor=null;
      CursorLoader cursorLoader=null;
      ImageView imageV;
      @SuppressLint("NewApi") @SuppressWarnings("deprecation")
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.search_list_activity);      
  
          cursorLoader=new CursorLoader(this,BirthdayProvider.CONTENT_URI,null, null,null,null);
  
          cursor=cursorLoader.loadInBackground();
  
          from=new String[]{BirthdayProvider.NAME,BirthdayProvider.NUMBER,BirthdayProvider.CATEGORY,BirthdayProvider.EVENT_TYPE,BirthdayProvider.EVENT_DAY,BirthdayProvider.WESTERN_ZODIAC};
  
          to=new int[]{R.id.title_name,R.id.sub_title_contact_number,R.id.sub_title_category,R.id.txtview_type_of_reminder,R.id.sub_title_birthdate,R.id.txtview_zodiac};
  
          if (cursor.moveToFirst()) {         
              adapter=new CustomSimpleCursor(this, R.layout.list_row, cursor, from, to);
              getListView().setAdapter(adapter);
          }
  
          else
          {
              emptyView=(TextView)getListView().findViewById(android.R.id.empty);
          }   
  
          getListView().setLongClickable(true);
  
          getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
              public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View v,int index, long arg3) {
                  TextView txtName=(TextView)v.findViewById(R.id.title_name);
                  name=txtName.getText().toString();
  
  
                  imageV=(ImageView)v.findViewById(R.id.ImageView02);
                  //imageV.setImageDrawable(getResources().getDrawable(R.drawable.rings_icon));
  
                  ImageView imgView=(ImageView)v.findViewById(R.id.list_image);
                  bitMap=((BitmapDrawable)imgView.getDrawable()).getBitmap();
  
                  TextView label=(TextView)v.findViewById(R.id.sub_title_contact_number);
  
                  longClickValue=label.getText().toString();
  
                  Intent intent=new Intent(getBaseContext(),ContactInfoMoreOption.class);
                  intent.putExtra("intentType","SearchListActivity");
                  intent.putExtra("longClickValue",longClickValue);
                  intent.putExtra("imgObj",imageV.toString());
                  startActivity(intent);
                  return true;
              }
          });     
  
      }
  
      @Override
      protected void onListItemClick(ListView l, View v, int position, long id) {
          super.onListItemClick(l, v, position, id);
  
          TextView txtName=(TextView)v.findViewById(R.id.title_name);
          name=txtName.getText().toString();
  
          ImageView imgView=(ImageView)v.findViewById(R.id.list_image);
          bitMap=((BitmapDrawable)imgView.getDrawable()).getBitmap();
  
          TextView txtBirthdate=(TextView)v.findViewById(R.id.sub_title_birthdate);
          birthdate=txtBirthdate.getText().toString();
  
          TextView txtTurnsAge=(TextView)v.findViewById(R.id.txtview_turns);
          turnsAge=txtTurnsAge.getText().toString();
  
          TextView txtWesterZodiac=(TextView)v.findViewById(R.id.txtview_zodiac);
          westerZodiac=txtWesterZodiac.getText().toString();
  
          TextView txtNextBD=(TextView)v.findViewById(R.id.txtview_next_bd);
          nextBD=txtNextBD.getText().toString();
  
          TextView txtEventType=(TextView)v.findViewById(R.id.txtview_type_of_reminder);
          eventType=txtEventType.getText().toString();
  
          Intent intent=new Intent(getBaseContext(),ContactInfoActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>CustomSimpleCursor.java</p>
  
  <pre><code>public class CustomSimpleCursor extends SimpleCursorAdapter{
  
      Typeface font;
      TextView txtDaysRemainigValue,txtTurnsAge;
  
      @SuppressWarnings("deprecation")
      public CustomSimpleCursor(Context context, int layout, Cursor c,
              String[] from, int[] to) {
          super(context, layout, c, from, to);
      }
      @Override
      public void bindView(View view, Context context, Cursor cursor) {
              super.bindView(view, context, cursor);            
  
              String todayBD = null;
  
              //Zodiac icon
              try {
                      ImageView thumbZodiacIcon = (ImageView) view.findViewById(R.id.ImageView01);
                      InputStream is = context.getResources().getAssets().open(cursor.getString(cursor.getColumnIndexOrThrow(BirthdayProvider.ZODIAC_ICON)));
                      Bitmap bit = /*BirthdayCalculation.ShrinkBitmap(is,200, 200);*/BitmapFactory.decodeStream(is);
                      thumbZodiacIcon.setImageBitmap(bit);
  
              } catch (Exception e1) {
                      e1.printStackTrace();
              }
  
           // Event icon 
              try {
                      ImageView thumbEventIcon = (ImageView) view.findViewById(R.id.ImageView02);
                      InputStream is = context.getResources().getAssets().open(cursor.getString(cursor.getColumnIndexOrThrow(BirthdayProvider.EVENT_ICON)));
                      Bitmap bit =BitmapFactory.decodeStream(is);
                      thumbEventIcon.setImageBitmap(bit);
  
              } catch (Exception e1) {
                      e1.printStackTrace();
              }
  
  
              //Contact photo
              try {
                  ImageView thumbContact = (ImageView) view.findViewById(R.id.list_image);
                  byte bitmapData[]=cursor.getBlob(cursor.getColumnIndex(BirthdayProvider.PHOTO));   
                  Bitmap bit = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
                  thumbContact.setImageBitmap(bit);
  
                  /*Animation localAnimation = AnimationUtils.loadAnimation(context,R.anim.fadein_image);
                  thumbContact.startAnimation(localAnimation);*/
  
          } catch (Exception e1) {
                  e1.printStackTrace();
          }
  
          //Days remaining for BirthDay  
  
           txtDaysRemainigValue=(TextView)view.findViewById(R.id.txtview_days_left);
  
           String year=cursor.getString(cursor.getColumnIndex(BirthdayProvider.EVENT_YEAR));
           String month=cursor.getString(cursor.getColumnIndex(BirthdayProvider.EVENT_MONTH));  
           String date=cursor.getString(cursor.getColumnIndex(BirthdayProvider.EVENT_DATE));
           String remainingDays=BirthdayCalculation.getDaysRemainingForNextBirthDay(year, month, date);
  
            Calendar today=Calendar.getInstance();
            int CMonth=(today.get(Calendar.MONDAY)+1);
            int CDate=(today.get(Calendar.DAY_OF_MONTH));
  
  
            txtDaysRemainigValue.setTextColor(Color.parseColor("#990000"));
            txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 27);
  
            //checking whether the BD is on TODAY
  
            if (remainingDays.equals("1") &amp;&amp; (CDate==Integer.parseInt(date) &amp;&amp; (CMonth)==Integer.parseInt(month))) {
  
                Log.v("else if executed","else if executed");
                Log.v("Remainin Days",remainingDays+" = Custom month"+cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+(CMonth)+"="+month);
               Log.v("Remainin Days",remainingDays+" = Custom date"+ cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+CDate+"="+date);
                txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
                txtDaysRemainigValue.setTextColor(Color.parseColor("#00CC33"));
              remainingDays="today".toLowerCase();
          }
  
            //checking whether the BD is on TOMORROW
            else if (remainingDays.equals("1")) {
  
               Log.v("Remainin Days",remainingDays+" = Custom month"+cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+(CMonth)+"="+month);
               Log.v("Remainin Days",remainingDays+" = Custom date"+ cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+CDate+"="+date);
                txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
                txtDaysRemainigValue.setTextColor(Color.parseColor("#FFFF00"));
              remainingDays="tomorrow".toLowerCase();
          }
  
  
          //checking how many days remaining BD
            else{
                remainingDays=BirthdayCalculation.getDaysRemainingForNextBirthDay(year, month, date);
                txtDaysRemainigValue.setTextSize(TypedValue.COMPLEX_UNIT_SP, 27);
                txtDaysRemainigValue.setTextColor(Color.parseColor("#990000"));
  
            }
            txtDaysRemainigValue=(TextView)view.findViewById(R.id.txtview_days_left);    
            font=Typeface.createFromAsset(context.getAssets(), "DS_DIGIB.ttf");
            txtDaysRemainigValue.setTypeface(font);
  
            //Log.v("Custom month",cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+(CMonth)+"="+month);
            //Log.v("Custom date", cursor.getString(cursor.getColumnIndex(BirthdayProvider.NAME))+"="+CDate+"="+date);
            txtDaysRemainigValue.setText(remainingDays);
  
        //Turns age
          font=Typeface.createFromAsset(context.getAssets(), "athletic.ttf");
          txtTurnsAge=(TextView)view.findViewById(R.id.txtview_turns);   
          //txtTurnsAge.setTypeface(font);
          String turnsAge=BirthdayCalculation.getAge(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(date));
          txtTurnsAge.setText(turnsAge);
  
  
        //Event week
          try {
  
              TextView txtEventWeek=(TextView)view.findViewById(R.id.txtview_next_bd);       
              String eventWeek=BirthdayCalculation.getDayOfWeek(year, month, date);
              font=Typeface.createFromAsset(context.getAssets(), "Comic Sans.ttf");
              txtEventWeek.setTypeface(font);
              txtEventWeek.setText(eventWeek);
  
          } catch (Exception e) {
              e.printStackTrace();
          } 
  
  
  
          // Contact Name
  
          TextView txtNumber=(TextView)view.findViewById(R.id.sub_title_contact_number);  
          font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
          txtNumber.setTypeface(font);
  
          TextView txtBirtgDay=(TextView)view.findViewById(R.id.sub_title_birthdate);  
          font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
          txtBirtgDay.setTypeface(font);
  
  
          TextView txtZodiac=(TextView)view.findViewById(R.id.TextView02);  
          font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
          txtZodiac.setTypeface(font);
  
          TextView txtZodiacValue=(TextView)view.findViewById(R.id.txtview_zodiac);  
          font=Typeface.createFromAsset(context.getAssets(), "Comic Sans.ttf");
          txtZodiacValue.setTypeface(font);
  
  
          TextView txtNextBD=(TextView)view.findViewById(R.id.TextView01);  
          font=Typeface.createFromAsset(context.getAssets(), "Roboto_Light.ttf");
          txtNextBD.setTypeface(font);
  
  
          TextView txtTurnsAge=(TextView)view.findViewById(R.id.list_image_arrow);  
          font=Typeface.createFromAsset(context.getAssets(), "athletic.ttf");
          txtTurnsAge.setTypeface(font);
  
          TextView txtDayRemainig=(TextView)view.findViewById(R.id.TextView04);    
          font=Typeface.createFromAsset(context.getAssets(), "athletic.ttf");
          txtDayRemainig.setTypeface(font);
  
  
  
  
  
          TextView txtTurnsAgeValue=(TextView)view.findViewById(R.id.txtview_turns);    
          font=Typeface.createFromAsset(context.getAssets(), "DS_DIGIB.ttf");
          txtTurnsAgeValue.setTypeface(font);
  
      }   
  }
  </code></pre>