weakwire
weakwire

Reputation: 9300

Is there any way to detect in an adapter,when getview() returned the view?,Android

So i have a list and i wan to check is the view is returned so i can call loadingAnimation.start() to make a imageview insite listview animate Let me tell you what i mean..

   public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
        if (convertView == null) {
             .... blah blah
          } else {

        holder = (ViewHolder) convertView.getTag();
                    //HERE IMAGE IS LOADED (SHOWN) SO .start() WILL WORK
        holder.loadingAnimation.start();

    }

using this code if i scroll down the animation starts to work.But the first initial positions of the listview don't work at the start

Note that if i make the call of loadingAnimation.start() inside the if (convertView == null) { or only outside the if .. else .. the animation will not ever work

So i need a way inside the adapter (doesn't have to be inside the getView) to get if a view is loaded (shown) Ty

EDIT I got it to work by emulation lag and then call the .start() to the animation

class emulateLag extends AsyncTask {
        protected Drawable doInBackground(Object... urls) {
            SystemClock.sleep(500);
            holder.loadingAnimation.start();
            return null;
        }

        protected void onPostExecute(Object result) {
        }
    }

    new emulateLag().execute("JUSTFORANIMATION");
        return convertView;

But i really don't like this approach so i keep the Question unanswered

Upvotes: 0

Views: 419

Answers (1)

Robby Pond
Robby Pond

Reputation: 73484

The best way to do it is to build it into your ImageView.

If you want to show an image from a url in an ImageView and show a loading animation while the image is loading you might want to check out the WebImageView from droid-Fu. This view does what you want.

Upvotes: 1

Related Questions