title: Refresh ListView with LazyAdapter in Android
body: <p>I am developing one application in that put all data in listview whatever coming from server for that i am using lazyadapter.Now i want to refresh all data in the listview(whenever click the button remove current data and update only new data i.e coming from server).i am using <code>notifyDataSetChanged().</code>its not working.please help me</p>
  
  <p>My code:</p>
  
  <pre><code>Activity
  
     public class JamLocationsActivity extends Activity   {
  
  
       private ListView listView;
      private String[] imageUrls;
      private ArrayList&lt;String&gt; imagesArray;
      private ArrayList&lt;String&gt; descArray;
      private ArrayList&lt;String&gt; dateTimeArray;
      private ArrayList&lt;String&gt; titleArray;
      private ArrayList&lt;String&gt; userArray;
      private LazyAdapter adapter;
      private ArrayList&lt;HashMap&lt;String, String&gt;&gt; latlngArray;
      private RecieveDataDTO receivingDatDto;
      private Button btn;
      private static ImageLoader imageLoader;
  
      @SuppressWarnings("unchecked")
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
            ActionBar bar = getActionBar();
               bar.setDisplayShowHomeEnabled(false);
               bar.setDisplayShowTitleEnabled(false);
               bar.setDisplayShowCustomEnabled(true);
              bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
              imageUrls=Constants.IMAGES;
  
              getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
              getActionBar().setCustomView(R.layout.action_bar_jamlocation);
             setContentView(R.layout.activity_jam_locations);
  
             imageLoader = ImageLoader.getInstance();
  
             JamLocationsActivity.imageLoader.init(ImageLoaderConfiguration.createDefault(this));
  
              imagesArray   = 
            (ArrayList&lt;String&gt;)getIntent().getSerializableExtra("imgArry");
              descArray     = 
             (ArrayList&lt;String&gt;)getIntent().getSerializableExtra("descArry");
              dateTimeArray = 
             (ArrayList&lt;String&gt;)getIntent().getSerializableExtra("dateTimeArry");
              titleArray    = 
             (ArrayList&lt;String&gt;)getIntent().getSerializableExtra("titleArr");
              userArray     = 
            (ArrayList&lt;String&gt;)getIntent().getSerializableExtra("userArr");
              latlngArray   =(ArrayList&lt;HashMap&lt;String, 
            String&gt;&gt;)getIntent().getSerializableExtra("latlngArr");
              Log.e("ARRAY", latlngArray.toString());
  
               receivingDatDto = new RecieveDataDTO();
              receivingDatDto.setImageArr(imagesArray);
              receivingDatDto.setTitleArr(titleArray);
              receivingDatDto.setUserArr(userArray);
              receivingDatDto.setDateTimeArr(dateTimeArray);
              receivingDatDto.setDescArr(descArray);
          //receivingDatDto.setLatLngArr(latlngArray);
           adapter = new LazyAdapter(JamLocationsActivity.this,receivingDatDto);
  
  
          listView=(ListView)findViewById(R.id.listView1);
          listView.setAdapter(adapter);
  
          btn.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                                 adapter.clearAdapter();
                    adapter.notifyDataSetChanged();
              }
          });
  
      }
  </code></pre>
  
  <p>LazyAdapter</p>
  
  <pre><code> public class LazyAdapter extends BaseAdapter{
  
      static Context context;
       private TextView timeTextView;
       private ListView listView;
  
  
      private String imageurl[]=null;
      private ArrayList&lt;String&gt; imgUrl;
      private ArrayList&lt;String&gt; images;
      private ArrayList&lt;String&gt; users;
      private ArrayList&lt;String&gt; dateTimes;
      private ArrayList&lt;String&gt; titles;
      private ArrayList&lt;String&gt; descriptions;
      private  ArrayList&lt;HashMap&lt;String, String&gt;&gt; latlngs;
  
      DisplayImageOptions doption=null;
      private ImageLoadingListener animateFirstListener =null;
      RecieveDataDTO receivedata= new RecieveDataDTO();
  
  
  
  
      // static ImageLoader imageLoader = ImageLoader.getInstance();
  
      public LazyAdapter(Context c,RecieveDataDTO dto){
          context=c;
          //this.imageurl=url;
      //  this.imgUrl = url;
          this.images = dto.getImageArr();
          this.users = dto.getUserArr();
          this.descriptions=dto.getDescArr();
          this.dateTimes=dto.getDateTimeArr();
          this.titles=dto.getTitleArr();
          this.latlngs=dto.getLatLngArr();
  
  
  
      }
  
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          //return imageurl.length;
          return users.size();
      }
  
      @Override
      public Object getItem(int arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          View view=convertView;
          ViewHolder viewHolder;
          Log.e("ADAPTER", images.toString());
          //viewHolder.mydate = 
        java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
          AQuery androidAQuery = new AQuery(context);
          if(convertView==null){
          LayoutInflater inflater=(LayoutInflater)context. 
             getSystemService(context.LAYOUT_INFLATER_SERVICE);
           view=inflater.inflate(R.layout.custom_data_list, null);
           viewHolder = new ViewHolder();
          viewHolder.shareBtn=(Button)view.findViewById(R.id.shareBtn);
          viewHolder.mapButton=(Button)view.findViewById(R.id.reportBtn);
          viewHolder.imageView2=(ImageView)view.findViewById(R.id.imageView2);
          viewHolder.imageView1=(ImageView)view.findViewById(R.id.imageView1);
  
  
  
           animateFirstListener = new AnimateFirstDisplayListener();
           viewHolder.addressTxtView=(TextView) view.findViewById(R.id.adddTextId);
           viewHolder.headTextView  = (TextView)view.findViewById(R.id.headTextId);
           viewHolder.dateTextView=(TextView) view.findViewById(R.id.dateTextId);
           viewHolder.userTextView=(TextView)view.findViewById(R.id.textView1);
           view.setTag(viewHolder);
          }else{
              viewHolder=(ViewHolder)view.getTag();
          }
           if(images.get(position).equals("")){
               viewHolder.imageView2.setVisibility(View.GONE);
           }
           else{
          androidAQuery.id(viewHolder.imageView2).image(images.get(position), true, true);
               /*ImageLoader imageLoader = ImageLoader.getInstance();
               imageLoader.displayImage(images.get(position), viewHolder.imageView2, 
            animateFirstListener);*/
           }
          // androidAQuery.id(viewHolder.imageView2).image(Constants.IMAGES[position], true, 
            true);
           viewHolder.addressTxtView.setText(descriptions.get(position));
           viewHolder.dateTextView.setText(dateTimes.get(position));
           viewHolder.headTextView.setText(titles.get(position));
           viewHolder.userTextView.setText(users.get(position));
           if(users.get(position).equals("police")){
  
          viewHolder.imageView1.setImageResource(R.drawable.common_signin_btn_icon_dark);
           }
           else{
  
         viewHolder.imageView1.setImageResource(R.drawable.common_signin_btn_icon_light);
           }
          /* ImageLoader imageLoader = ImageLoader.getInstance();
           imageLoader.displayImage("", viewHolder.imageView2);
           imageLoader.displayImage(imgUrl.get(position), viewHolder.imageView2, animateFirstListener);*/
  
          viewHolder.shareBtn.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(context,AndroidFacebookSample.class);
                  intent.putExtra("fbVal", descriptions.get(position));
                  intent.putExtra("trTime", dateTimes.get(position));
                  context.startActivity(intent);
              }
          });
          viewHolder.mapButton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(context,SingleJamLocationActivity.class);
  
                  context.startActivity(intent);
  
              }
          });
          viewHolder.imageView2.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Log.e("You", "Clicked Me");
                  Intent intent = new Intent(context, ImagePerActivity.class);
                  intent.putExtra("imageurlpostion", images);
                  intent.putExtra("imagepostion", position);
                  context.startActivity(intent);
  
              }
          });
  
  
          return view;
      }
      private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
  
          static final List&lt;String&gt; displayedImages = Collections.synchronizedList(new 
        LinkedList&lt;String&gt;());
  
          @Override
          public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
              if (loadedImage != null) {
                  ImageView imageView = (ImageView) view;
                  boolean firstDisplay = !displayedImages.contains(imageUri);
                  if (firstDisplay) {
                      FadeInBitmapDisplayer.animate(imageView, 500);
                      displayedImages.add(imageUri);
                  }
              }
          }
      }
  </code></pre>