在android中拖放带有图像和文本的listview

在android中拖放带有图像和文本的listview,android,listview,drag-and-drop,Android,Listview,Drag And Drop,我想在我的应用程序中实现列表项的拖放。我接着说,它适用于只包含文本的列表。我将惰性列表与图像以及拖放集成在一起。但是,当我拖动项目时,拖动的项目会转到实际位置。拖动项下方的项将从列表中删除。在我取下手指后,拖动的项目不会移动到我希望的位置。这个代码有什么问题 main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/re

我想在我的应用程序中实现列表项的拖放。我接着说,它适用于只包含文本的列表。我将惰性列表与图像以及拖放集成在一起。但是,当我拖动项目时,拖动的项目会转到实际位置。拖动项下方的项将从列表中删除。在我取下手指后,拖动的项目不会移动到我希望的位置。这个代码有什么问题

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.listviewdragginganimation.DynamicListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1"/>
    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:text="Clear Cache"/>
</LinearLayout>

DynamicListView.Java:

package com.listviewdragginganimation;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;

import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class DynamicListView extends ListView {

    private final int SMOOTH_SCROLL_AMOUNT_AT_EDGE = 15;
    private final int MOVE_DURATION = 150;
    private final int LINE_THICKNESS = 15;

    public ArrayList<String> mCheeseList;

    private int mLastEventY = -1;

    private int mDownY = -1;
    private int mDownX = -1;

    private int mTotalOffset = 0;

    private boolean mCellIsMobile = false;
    private boolean mIsMobileScrolling = false;
    private int mSmoothScrollAmountAtEdge = 0;

    private final int INVALID_ID = -1;
    private long mAboveItemId = INVALID_ID;
    private long mMobileItemId = INVALID_ID;
    private long mBelowItemId = INVALID_ID;

    private BitmapDrawable mHoverCell;
    private Rect mHoverCellCurrentBounds;
    private Rect mHoverCellOriginalBounds;

    private final int INVALID_POINTER_ID = -1;
    private int mActivePointerId = INVALID_POINTER_ID;

    private boolean mIsWaitingForScrollFinish = false;
    private int mScrollState = OnScrollListener.SCROLL_STATE_IDLE;

    public DynamicListView(Context context) {
        super(context);
        init(context);
    }

    public DynamicListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    public DynamicListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public void init(Context context) {
        setOnItemLongClickListener(mOnItemLongClickListener);
        setOnScrollListener(mScrollListener);
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        mSmoothScrollAmountAtEdge = (int) (SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density);
    }


    private AdapterView.OnItemLongClickListener mOnItemLongClickListener = new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos,
                long id) {
            mTotalOffset = 0;

            int position = pointToPosition(mDownX, mDownY);
            int itemNum = position - getFirstVisiblePosition();

            View selectedView = getChildAt(itemNum);
            mMobileItemId = getAdapter().getItemId(position);
            mHoverCell = getAndAddHoverView(selectedView);
            selectedView.setVisibility(INVISIBLE);

            mCellIsMobile = true;

            updateNeighborViewsForID(mMobileItemId);

            return true;
        }
    };


    private BitmapDrawable getAndAddHoverView(View v) {

        int w = v.getWidth();
        int h = v.getHeight();
        int top = v.getTop();
        int left = v.getLeft();

        Bitmap b = getBitmapWithBorder(v);

        BitmapDrawable drawable = new BitmapDrawable(getResources(), b);

        mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
        mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);

        drawable.setBounds(mHoverCellCurrentBounds);

        return drawable;
    }

    /** Draws a black border over the screenshot of the view passed in. */
    private Bitmap getBitmapWithBorder(View v) {
        Bitmap bitmap = getBitmapFromView(v);
        Canvas can = new Canvas(bitmap);

        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(LINE_THICKNESS);
        paint.setColor(Color.BLACK);

        can.drawBitmap(bitmap, 0, 0, null);
        can.drawRect(rect, paint);

        return bitmap;
    }

    /** Returns a bitmap showing a screenshot of the view passed in. */
    private Bitmap getBitmapFromView(View v) {
        Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        v.draw(canvas);
        return bitmap;
    }


    private void updateNeighborViewsForID(long itemID) {
        int position = getPositionForID(itemID);
        LazyAdapter adapter = ((LazyAdapter) getAdapter());
        mAboveItemId = adapter.getItemId(position - 1);
        mBelowItemId = adapter.getItemId(position + 1);
    }

    /** Retrieves the view in the list corresponding to itemID */
    public View getViewForID(long itemID) {
        int firstVisiblePosition = getFirstVisiblePosition();
        LazyAdapter adapter = ((LazyAdapter) getAdapter());
        for (int i = 0; i < getChildCount(); i++) {
            View v = getChildAt(i);
            int position = firstVisiblePosition + i;
            long id = adapter.getItemId(position);
            if (id == itemID) {
                return v;
            }
        }
        return null;
    }

    /** Retrieves the position in the list corresponding to itemID */
    public int getPositionForID(long itemID) {
        View v = getViewForID(itemID);
        if (v == null) {
            return -1;
        } else {
            return getPositionForView(v);
        }
    }


    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (mHoverCell != null) {
            mHoverCell.draw(canvas);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mDownX = (int) event.getX();
            mDownY = (int) event.getY();
            mActivePointerId = event.getPointerId(0);
            break;
        case MotionEvent.ACTION_MOVE:
            if (mActivePointerId == INVALID_POINTER_ID) {
                break;
            }

            int pointerIndex = event.findPointerIndex(mActivePointerId);

            mLastEventY = (int) event.getY(pointerIndex);
            int deltaY = mLastEventY - mDownY;

            if (mCellIsMobile) {
                mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
                        mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
                mHoverCell.setBounds(mHoverCellCurrentBounds);
                invalidate();
                // Log.v("handle switch 1","1");
                handleCellSwitch();
                // Log.v("handle switch 2","2");
                mIsMobileScrolling = false;
                handleMobileCellScroll();

                return false;
            }
            break;
        case MotionEvent.ACTION_UP:
            touchEventsEnded();
            break;
        case MotionEvent.ACTION_CANCEL:
            touchEventsCancelled();
            break;
        case MotionEvent.ACTION_POINTER_UP:

            pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            final int pointerId = event.getPointerId(pointerIndex);
            if (pointerId == mActivePointerId) {
                touchEventsEnded();
            }
            break;
        default:
            break;
        }

        return super.onTouchEvent(event);
    }


    private void handleCellSwitch() {
        final int deltaY = mLastEventY - mDownY;
        int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;

        View belowView = getViewForID(mBelowItemId);
        View mobileView = getViewForID(mMobileItemId);
        View aboveView = getViewForID(mAboveItemId);

        boolean isBelow = (belowView != null)
                && (deltaYTotal > belowView.getTop());
        boolean isAbove = (aboveView != null)
                && (deltaYTotal < aboveView.getTop());

        if (isBelow || isAbove) {

            final long switchItemID = isBelow ? mBelowItemId : mAboveItemId;
            View switchView = isBelow ? belowView : aboveView;
            final int originalItem = getPositionForView(mobileView);

            if (switchView == null) {
                updateNeighborViewsForID(mMobileItemId);
                return;
            }
            Log.v("swapElements switch 1", "1");
            Log.v("swapElements originalItem 1", originalItem + "");
            Log.v("swapElements switchView 1", "" + switchView);

            setCheeseList(MainActivity.mCheeseList);
            Log.v("mCheeseList item", mCheeseList.get(originalItem));
            swapElements(mCheeseList, originalItem,
                    getPositionForView(switchView));
            Log.v("swapElements switch 2", "2");
            // ((BaseAdapter) getAdapter()).notifyDataSetChanged();
            MainActivity.adapter.notifyDataSetChanged();
            mDownY = mLastEventY;

            final int switchViewStartTop = switchView.getTop();

            mobileView.setVisibility(View.VISIBLE);
            switchView.setVisibility(View.INVISIBLE);

            updateNeighborViewsForID(mMobileItemId);

            final ViewTreeObserver observer = getViewTreeObserver();
            observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                public boolean onPreDraw() {
                    observer.removeOnPreDrawListener(this);

                    View switchView = getViewForID(switchItemID);

                    mTotalOffset += deltaY;

                    int switchViewNewTop = switchView.getTop();
                    int delta = switchViewStartTop - switchViewNewTop;

                    switchView.setTranslationY(delta);

                    ObjectAnimator animator = ObjectAnimator.ofFloat(
                            switchView, View.TRANSLATION_Y, 0);
                    animator.setDuration(MOVE_DURATION);
                    animator.start();

                    return true;
                }
            });
        }
    }

    private void swapElements(ArrayList<String> arrayList, int indexOne,
            int indexTwo) {
        Log.v("index one", indexOne + "");
        Log.v("index two", indexTwo + "");
        Log.v("temp", arrayList.get(indexOne));
        String temp = arrayList.get(indexOne);

        arrayList.set(indexOne, arrayList.get(indexTwo));
        arrayList.set(indexTwo, temp);
    }

    /**
     * Resets all the appropriate fields to a default state while also animating
     * the hover cell back to its correct location.
     */
    private void touchEventsEnded() {
        final View mobileView = getViewForID(mMobileItemId);
        if (mCellIsMobile || mIsWaitingForScrollFinish) {
            mCellIsMobile = false;
            mIsWaitingForScrollFinish = false;
            mIsMobileScrolling = false;
            mActivePointerId = INVALID_POINTER_ID;

            // If the autoscroller has not completed scrolling, we need to wait
            // for it to
            // finish in order to determine the final location of where the
            // hover cell
            // should be animated to.
            if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) {
                mIsWaitingForScrollFinish = true;
                return;
            }

            mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
                    mobileView.getTop());

            ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(
                    mHoverCell, "bounds", sBoundEvaluator,
                    mHoverCellCurrentBounds);
            hoverViewAnimator
                    .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(
                                ValueAnimator valueAnimator) {
                            invalidate();
                        }
                    });
            hoverViewAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    mAboveItemId = INVALID_ID;
                    mMobileItemId = INVALID_ID;
                    mBelowItemId = INVALID_ID;
                    mobileView.setVisibility(VISIBLE);
                    mHoverCell = null;
                    setEnabled(true);
                    invalidate();
                }
            });
            hoverViewAnimator.start();
        } else {
            touchEventsCancelled();
        }
    }

    /**
     * Resets all the appropriate fields to a default state.
     */
    private void touchEventsCancelled() {
        View mobileView = getViewForID(mMobileItemId);
        if (mCellIsMobile) {
            mAboveItemId = INVALID_ID;
            mMobileItemId = INVALID_ID;
            mBelowItemId = INVALID_ID;
            mobileView.setVisibility(VISIBLE);
            mHoverCell = null;
            invalidate();
        }
        mCellIsMobile = false;
        mIsMobileScrolling = false;
        mActivePointerId = INVALID_POINTER_ID;
    }

    /**
     * This TypeEvaluator is used to animate the BitmapDrawable back to its
     * final location when the user lifts his finger by modifying the
     * BitmapDrawable's bounds.
     */
    private final static TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {
        public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
            return new Rect(interpolate(startValue.left, endValue.left,
                    fraction), interpolate(startValue.top, endValue.top,
                    fraction), interpolate(startValue.right, endValue.right,
                    fraction), interpolate(startValue.bottom, endValue.bottom,
                    fraction));
        }

        public int interpolate(int start, int end, float fraction) {
            return (int) (start + fraction * (end - start));
        }
    };


    private void handleMobileCellScroll() {
        mIsMobileScrolling = handleMobileCellScroll(mHoverCellCurrentBounds);
    }


    public boolean handleMobileCellScroll(Rect r) {
        int offset = computeVerticalScrollOffset();
        int height = getHeight();
        int extent = computeVerticalScrollExtent();
        int range = computeVerticalScrollRange();
        int hoverViewTop = r.top;
        int hoverHeight = r.height();

        if (hoverViewTop <= 0 && offset > 0) {
            smoothScrollBy(-mSmoothScrollAmountAtEdge, 0);
            return true;
        }

        if (hoverViewTop + hoverHeight >= height && (offset + extent) < range) {
            smoothScrollBy(mSmoothScrollAmountAtEdge, 0);
            return true;
        }

        return false;
    }

    public void setCheeseList(ArrayList<String> cheeseList) {
        mCheeseList = cheeseList;
    }


    private AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener() {

        private int mPreviousFirstVisibleItem = -1;
        private int mPreviousVisibleItemCount = -1;
        private int mCurrentFirstVisibleItem;
        private int mCurrentVisibleItemCount;
        private int mCurrentScrollState;

        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            mCurrentFirstVisibleItem = firstVisibleItem;
            mCurrentVisibleItemCount = visibleItemCount;

            mPreviousFirstVisibleItem = (mPreviousFirstVisibleItem == -1) ? mCurrentFirstVisibleItem
                    : mPreviousFirstVisibleItem;
            mPreviousVisibleItemCount = (mPreviousVisibleItemCount == -1) ? mCurrentVisibleItemCount
                    : mPreviousVisibleItemCount;

            checkAndHandleFirstVisibleCellChange();
            checkAndHandleLastVisibleCellChange();

            mPreviousFirstVisibleItem = mCurrentFirstVisibleItem;
            mPreviousVisibleItemCount = mCurrentVisibleItemCount;
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            mCurrentScrollState = scrollState;
            mScrollState = scrollState;
            isScrollCompleted();
        }


        private void isScrollCompleted() {
            if (mCurrentVisibleItemCount > 0
                    && mCurrentScrollState == SCROLL_STATE_IDLE) {
                if (mCellIsMobile && mIsMobileScrolling) {
                    handleMobileCellScroll();
                } else if (mIsWaitingForScrollFinish) {
                    touchEventsEnded();
                }
            }
        }

        /**
         * Determines if the listview scrolled up enough to reveal a new cell at
         * the top of the list. If so, then the appropriate parameters are
         * updated.
         */
        public void checkAndHandleFirstVisibleCellChange() {
            if (mCurrentFirstVisibleItem != mPreviousFirstVisibleItem) {
                if (mCellIsMobile && mMobileItemId != INVALID_ID) {
                    updateNeighborViewsForID(mMobileItemId);
                    handleCellSwitch();
                }
            }
        }

        /**
         * Determines if the listview scrolled down enough to reveal a new cell
         * at the bottom of the list. If so, then the appropriate parameters are
         * updated.
         */
        public void checkAndHandleLastVisibleCellChange() {
            int currentLastVisibleItem = mCurrentFirstVisibleItem
                    + mCurrentVisibleItemCount;
            int previousLastVisibleItem = mPreviousFirstVisibleItem
                    + mPreviousVisibleItemCount;
            if (currentLastVisibleItem != previousLastVisibleItem) {
                if (mCellIsMobile && mMobileItemId != INVALID_ID) {
                    updateNeighborViewsForID(mMobileItemId);
                    handleCellSwitch();
                }
            }
        }
    };
}
package com.listViewDragingAnimation;
导入android.animation.Animator;
导入android.animation.AnimatorListenerAdapter;
导入android.animation.ObjectAnimator;
导入android.animation.TypeEvaluator;
导入android.animation.ValueAnimator;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.graphics.Canvas;
导入android.graphics.Color;
导入android.graphics.Paint;
导入android.graphics.Rect;
导入android.graphics.drawable.BitmapDrawable;
导入android.util.AttributeSet;
导入android.util.DisplayMetrics;
导入android.util.Log;
导入android.view.MotionEvent;
导入android.view.view;
导入android.view.ViewTreeObserver;
导入android.widget.AbsListView;
导入android.widget.AdapterView;
导入android.widget.BaseAdapter;
导入android.widget.ListView;
导入java.util.ArrayList;
公共类DynamicListView扩展了ListView{
私有最终整型平滑\u滚动\u数量\u边缘=15;
私人最终整数移动持续时间=150;
私有最终内部线厚度=15;
公共ArrayList mCheeseList;
private int mLastEventY=-1;
private int mDownY=-1;
private int mDownX=-1;
私有int mTotalOffset=0;
私有布尔值mCellIsMobile=false;
私有布尔值mIsMobileScrolling=false;
private int mSmoothScrollAmountAtEdge=0;
私有final int INVALID_ID=-1;
private long mAboveItemId=无效的\u ID;
private long mMobileItemId=无效的\u ID;
private long mBelowItemId=无效的\u ID;
专用位图可绘制MH超小区;
私有Rect-mhcolcurrentBounds;
私有Rect-mHoverCellOriginalBounds;
私有final int无效\u指针\u ID=-1;
private int mActivePointerId=无效的\u指针\u ID;
私有布尔值mIsWaitingForScrollFinish=false;
private int mScrollState=onscrollllistener.SCROLL\u STATE\u IDLE;
公共DynamicListView(上下文){
超级(上下文);
init(上下文);
}
公共DynamicListView(上下文上下文、属性集属性、int-defStyle){
超级(上下文、属性、定义样式);
init(上下文);
}
公共DynamicList视图(上下文、属性集属性){
超级(上下文,attrs);
init(上下文);
}
公共void init(上下文){
设置长ClickListener(监视器长ClickListener);
setOnScrollListener(mScrollListener);
DisplayMetrics=context.getResources().getDisplayMetrics();
mSmoothScrollAmountAtEdge=(int)(平滑滚动边缘处的数量/metrics.density);
}
私有AdapterView.OnItemLongClickListener监视器LongClickListener=new AdapterView.OnItemLongClickListener(){
长点击(AdapterView arg0、视图arg1、int pos、,
长id){
mTotalOffset=0;
int位置=点位置(mDownX,mDownY);
int itemNum=position-getFirstVisiblePosition();
View selectedView=getChildAt(itemNum);
mMobileItemId=getAdapter().getItemId(位置);
mHoverCell=GetAndAddressHoverView(selectedView);
selectedView.setVisibility(不可见);
mCellIsMobile=true;
updateNeighborViewsForID(mMobileItemId);
返回true;
}
};
私有位图可绘制getAndAddHoverView(视图v){
int w=v.getWidth();
inth=v.getHeight();
int top=v.getTop();
int left=v.getLeft();
位图b=getBitmapWithBorder(v);
BitmapDrawable drawable=新的BitmapDrawable(getResources(),b);
mHoverCellOriginalBounds=新矩形(左、上、左+w、上+h);
mHoverCellCurrentBounds=新的Rect(mHoverCellOriginalBounds);
可拉深的立根(MH);
回拉;
}
/**在传入视图的屏幕截图上绘制黑色边框*/
私有位图getBitmapWithBorder(视图v){
位图位图=getBitmapFromView(v);
Canvas can=新画布(位图);
Rect Rect=new Rect(0,0,bitmap.getWidth(),bitmap.getHeight());
油漆=新油漆();
绘制.设置样式(绘制.样式.笔划);
油漆。设置行程宽度(线条厚度);
油漆。设置颜色(颜色。黑色);
can.drawBitmap(位图,0,0,null);
can.drawRect(rect,paint);
返回位图;
}
/**返回显示传入视图屏幕截图的位图*/
私有位图getBitmapFromView(视图v){
位图Bitmap=Bitmap.createBitmap(v.getWidth(),v.getHeight(),
位图.Config.ARGB_8888);
画布=新画布(位图);
v、 绘画(画布);
返回位图;
}
私有void updateNeighborViewsForID(长项目ID){
int position=getPositionForID(itemID);
LazyAdapter=((LazyAdapter)getAdapter());
mAboveItemId=adapter.getItemId(位置-1);
mBelowItemId=adapter.getItemId(位置+1);
}
/**检索与itemID对应的列表中的视图*/
公共视图getViewForID(长项目ID){
int firstVisiblePosition=getFirstVisiblePosition();
LazyAdapter=((LazyAdapter)getAdapter());
对于(int i=0;ipackage com.listviewdragginganimation;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<String> data=new ArrayList<String>();
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 



    public LazyAdapter(MainActivity a, ArrayList<String> mCheeseList) {
        // TODO Auto-generated constructor stub
         activity = a;
         data=mCheeseList;
         inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item, null);

        TextView text=(TextView)vi.findViewById(R.id.text);;
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        text.setText("item "+position);
        imageLoader.DisplayImage(data.get(position), image);
        return vi;
    }
}
package com.listviewdragginganimation;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity {

    ListView list;
   static LazyAdapter adapter;
   static ArrayList<String>mCheeseList = new ArrayList<String>();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        for (int i = 0; i < mStrings.length; ++i) {
            mCheeseList.add(mStrings[i]);
        }
        list=(ListView)findViewById(R.id.list);
        adapter=new LazyAdapter(this, mCheeseList);
        list.setAdapter(adapter);

        Button b=(Button)findViewById(R.id.button1);
        b.setOnClickListener(listener);
    }

    @Override
    public void onDestroy()
    {
        list.setAdapter(null);
        super.onDestroy();
    }

    public OnClickListener listener=new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            adapter.imageLoader.clearCache();
            adapter.notifyDataSetChanged();
        }
    };

    private String[] mStrings={
            "http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter.png",
            "http://a3.twimg.com/profile_images/740897825/AndroidCast-350_normal.png",
            "http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg",
            "http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg",
            "http://a1.twimg.com/profile_images/97470808/icon_normal.png",
            "http://a3.twimg.com/profile_images/511790713/AG.png",
            "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
            "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
            "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
            "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg",
            "http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png",
            "http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
            "http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",


    };
}